mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
merged Tx Delay https://github.com/proddy/EMS-ESP/pull/113
This commit is contained in:
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- Improved Tx code, by @Susis Strolch [(pull request 113)](https://github.com/proddy/EMS-ESP/pull/113). Use `set_txdelay 2`
|
||||||
|
|
||||||
## [1.7.0] 2019-05-11
|
## [1.7.0] 2019-05-11
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -687,7 +687,7 @@ void _ems_readTelegram(uint8_t * telegram, uint8_t length) {
|
|||||||
_last_emsPollFrequency = EMS_RxTelegram.timestamp;
|
_last_emsPollFrequency = EMS_RxTelegram.timestamp;
|
||||||
|
|
||||||
// check first for a Poll for us
|
// check first for a Poll for us
|
||||||
if (value == (EMS_ID_ME | 0x80)) {
|
if ((value & 0x7F) == EMS_ID_ME) {
|
||||||
EMS_Sys_Status.emsTxCapable = true;
|
EMS_Sys_Status.emsTxCapable = true;
|
||||||
|
|
||||||
// do we have something to send thats waiting in the Tx queue?
|
// do we have something to send thats waiting in the Tx queue?
|
||||||
|
|||||||
@@ -130,10 +130,10 @@ void ICACHE_FLASH_ATTR emsuart_init() {
|
|||||||
// disable esp debug which will go to Tx and mess up the line
|
// disable esp debug which will go to Tx and mess up the line
|
||||||
system_set_os_print(0); // https://github.com/espruino/Espruino/issues/655
|
system_set_os_print(0); // https://github.com/espruino/Espruino/issues/655
|
||||||
|
|
||||||
// swap Rx and Tx pins to use GPIO13 (D7) and GPIO15 (D8) respectively
|
// swap Rx and Tx pins to use GPIO13 (D7) and GPIO15 (D8) respectively
|
||||||
#ifndef NO_UART_SWAP
|
#ifndef NO_UART_SWAP
|
||||||
system_uart_swap();
|
system_uart_swap();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ETS_UART_INTR_ATTACH(emsuart_rx_intr_handler, NULL);
|
ETS_UART_INTR_ATTACH(emsuart_rx_intr_handler, NULL);
|
||||||
ETS_UART_INTR_ENABLE();
|
ETS_UART_INTR_ENABLE();
|
||||||
@@ -195,20 +195,20 @@ void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) {
|
|||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
|
|
||||||
// backward compatibility
|
// backward compatibility
|
||||||
if (EMS_Sys_Status.emsTxDelay<2) {
|
if (EMS_Sys_Status.emsTxDelay < 2) {
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
for (uint8_t i = 0; i < len; i++) {
|
||||||
USF(EMSUART_UART) = buf[i];
|
USF(EMSUART_UART) = buf[i];
|
||||||
|
|
||||||
// check if we need to force a delay to slow down Tx
|
// check if we need to force a delay to slow down Tx
|
||||||
// https://github.com/proddy/EMS-ESP/issues/23#
|
// https://github.com/proddy/EMS-ESP/issues/23#
|
||||||
if (EMS_Sys_Status.emsTxDelay==1) {
|
if (EMS_Sys_Status.emsTxDelay == 1) {
|
||||||
delayMicroseconds(EMS_TX_BRK_WAIT);
|
delayMicroseconds(EMS_TX_BRK_WAIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emsuart_tx_brk(); // send <BRK>
|
emsuart_tx_brk(); // send <BRK>
|
||||||
} else {
|
} else {
|
||||||
// smart Tx
|
// smart Tx
|
||||||
#define UART_BIT_TIME 104 // bit time @9600 baud
|
#define UART_BIT_TIME 104 // bit time @9600 baud
|
||||||
|
|
||||||
ETS_UART_INTR_DISABLE(); // disable rx interrupt
|
ETS_UART_INTR_DISABLE(); // disable rx interrupt
|
||||||
emsuart_flush_fifos();
|
emsuart_flush_fifos();
|
||||||
@@ -216,7 +216,7 @@ void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) {
|
|||||||
|
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
for (uint8_t i = 0; i < len; i++) {
|
||||||
USF(EMSUART_UART) = buf[i]; // send byte
|
USF(EMSUART_UART) = buf[i]; // send byte
|
||||||
delayMicroseconds(10*UART_BIT_TIME);
|
delayMicroseconds(10 * UART_BIT_TIME);
|
||||||
|
|
||||||
/* wait until
|
/* wait until
|
||||||
* ° loopback char is received
|
* ° loopback char is received
|
||||||
@@ -225,14 +225,13 @@ void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) {
|
|||||||
* ° Break detected (bus collision) - not handled now...
|
* ° Break detected (bus collision) - not handled now...
|
||||||
*/
|
*/
|
||||||
for (uint8_t l = 0; l < 13; l++) {
|
for (uint8_t l = 0; l < 13; l++) {
|
||||||
if (((USS(EMSUART_UART) >> USRXC) & 0xFF)
|
if (((USS(EMSUART_UART) >> USRXC) & 0xFF) || (U0IS & ((1 << UIFF) | (1 << UITO) | (1 << UIBD))))
|
||||||
|| (U0IS & ((1 << UIFF) | (1 << UITO) | (1 << UIBD))))
|
|
||||||
break;
|
break;
|
||||||
delayMicroseconds(UART_BIT_TIME / 8); // ~13µs
|
delayMicroseconds(UART_BIT_TIME / 8); // ~13µs
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t break_detect = (U0IS & (1 << UIBD)); // keep break detect interrupt
|
uint32_t break_detect = (U0IS & (1 << UIBD)); // keep break detect interrupt
|
||||||
(void) (USF(EMSUART_UART)); // read out fifo, also clears FIFO counter
|
(void)(USF(EMSUART_UART)); // read out fifo, also clears FIFO counter
|
||||||
U0IC = (1 << UIFF) | (1 << UITO) | (1 << UIBD); // clear pending interrupts
|
U0IC = (1 << UIFF) | (1 << UITO) | (1 << UIBD); // clear pending interrupts
|
||||||
if (break_detect)
|
if (break_detect)
|
||||||
break; // collision / abort from master
|
break; // collision / abort from master
|
||||||
@@ -256,5 +255,5 @@ void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) {
|
|||||||
*/
|
*/
|
||||||
void ICACHE_FLASH_ATTR emsuart_tx_poll() {
|
void ICACHE_FLASH_ATTR emsuart_tx_poll() {
|
||||||
static uint8_t buf[] = {EMS_ID_ME};
|
static uint8_t buf[] = {EMS_ID_ME};
|
||||||
emsuart_tx_buffer(buf,1);
|
emsuart_tx_buffer(buf, 1);
|
||||||
}
|
}
|
||||||
@@ -6,5 +6,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define APP_NAME "EMS-ESP"
|
#define APP_NAME "EMS-ESP"
|
||||||
#define APP_VERSION "1.8.0b1"
|
#define APP_VERSION "1.8.0b2"
|
||||||
#define APP_HOSTNAME "ems-esp"
|
#define APP_HOSTNAME "ems-esp"
|
||||||
|
|||||||
Reference in New Issue
Block a user