Hello everyone,
can someone help me using the USART TX interrupt?
I can't understand how to initiate a TX streaming without using TXSTA.TRMT polling
Thank you
CG
USART TX interrupt
-
- Posts: 18
- Joined: 11 Apr 2017 06:17
- Location: Italy
Re: USART TX interrupt
Hi,
no one is using the usart tx interrupt?
I did a simple routine (a state machine) that avoids continuous polling of TXSTA.TRMT, for my modbus implementation, but is going to be heavier than a simple while waiting for trasmission to complete:
(I have a rs485 driver with tx and rx enables, I put the rx into standby when unused to save power)
Really nobody can help me?
Thank you
CG
no one is using the usart tx interrupt?
I did a simple routine (a state machine) that avoids continuous polling of TXSTA.TRMT, for my modbus implementation, but is going to be heavier than a simple while waiting for trasmission to complete:
(I have a rs485 driver with tx and rx enables, I put the rx into standby when unused to save power)
Code: Select all
typedef enum __TXStatus {
TX_INIT,
TX_WAIT,
TX_ENABLED,
TX_STOP
} _TXStatus;
unsigned char g_ucTXStatus = TX_INIT;
void ModbusSerialTXBufferUnloadTask (void) {
//scarica completamente il buffer di uscita
//controlla se il buffer non è vuoto e fa il ritardo
unsigned char ucONBitCounter = 0;
unsigned char ucTemp;
switch (g_ucTXStatus) {
case TX_INIT: if (FifoEmpty(&g_SerialTX)) break;
if (g_b_TMR3clock1mSSerialReplyCounter < MODBUS_RX_TO_TX_DELAY) break;
//inizia la comunicazione
DOenRXua = 1;
Delay_us(1);
DOenTXua = 1;
Delay_us(1);
g_ucTXStatus = TX_ENABLED;
break;
case TX_ENABLED: if (FifoEmpty(&g_SerialTX)) {
g_ucTXStatus = TX_STOP;
break;
}
ucTemp = FifoPop(&g_SerialTX);
if (g_ucUARTParityType) {
if (ucTemp.F0) ucONBitCounter++;
if (ucTemp.F1) ucONBitCounter++;
if (ucTemp.F2) ucONBitCounter++;
if (ucTemp.F3) ucONBitCounter++;
if (ucTemp.F4) ucONBitCounter++;
if (ucTemp.F5) ucONBitCounter++;
if (ucTemp.F6) ucONBitCounter++;
if (ucTemp.F7) ucONBitCounter++;
switch (g_ucUARTParityType) {
case ODD : if (ucONBitCounter.F0) TXSTA.TX9D = 1; break;
case EVEN : if (!ucONBitCounter.F0) TXSTA.TX9D = 1; break;
case MARK : TXSTA.TX9D = 1; break;
case SPACE : TXSTA.TX9D = 0; break;
}
}
// UART1_Write(ucTemp);
TXREG1 = ucTemp;
g_ucTXStatus = TX_WAIT;
break;
case TX_WAIT: if(!TXSTA.TRMT) break;
g_ucTXStatus = TX_ENABLED;
break;
case TX_STOP: DOenTXua = 0;
Delay_us(1);
DOenRXua = 0;
g_ucTXStatus = TX_INIT;
break;
default: g_ucTXStatus = TX_INIT;
break;
}
}
Thank you
CG
- filip.grujcic
- Posts: 822
- Joined: 14 May 2018 08:34
Re: USART TX interrupt
Hello,
What MCU are you using?
I advise you to consult the datasheet for your MCU, in order to learn how to use the TX interrupt.
Kind regards,
What MCU are you using?
I advise you to consult the datasheet for your MCU, in order to learn how to use the TX interrupt.
Kind regards,
Filip Grujcic
-
- Posts: 18
- Joined: 11 Apr 2017 06:17
- Location: Italy
Re: USART TX interrupt
PIC18F67K22filip.grujcic wrote:Hello,
What MCU are you using?
I advise you to consult the datasheet for your MCU, in order to learn how to use the TX interrupt.
Kind regards,
thank you
Best
CG
- filip.grujcic
- Posts: 822
- Joined: 14 May 2018 08:34
Re: USART TX interrupt
Hello,
Could you please explain why and where exactly you are trying to implement a TX interrupt?
From the code you posted, I'm not sure I understand the problem fully.
Best regards,
Could you please explain why and where exactly you are trying to implement a TX interrupt?
From the code you posted, I'm not sure I understand the problem fully.
Best regards,
Filip Grujcic