Hi,
I am currently using PIC12F/LF1822 MCU,
for which I have generated USART and WDGT code using MPLAB MCC code generator, And they are working fine...
But I have a situation here as follows,
I have a requirement of receiving 19 bytes of frame over USART. Once received 19 Bytes are passed to a handler for further processing.
Info: USART is ISR based.
I have started sending the Data byte by byte over USART using Hercules tool on my laptop.
I am facing a WDGT reset on random upon the reception characters.
The following is the USART Rx ISR code for better understanding
,
Code C - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| #define EUSART_RX_BUFFER_SIZE 19
volatile uint8_t eusartRxHead = 0;
volatile uint8_t eusartRxBuffer[EUSART_RX_BUFFER_SIZE];
volatile uint8_t eusartRxCount;
void EUSART_Receive_ISR(void)
{
volatile uint8_t u8Char;
if(1 == RCSTAbits.OERR)
{
// EUSART error - restart
RCSTAbits.CREN = 0;
RCSTAbits.CREN = 1;
}
u8Char = RCREG;
CLRWDT(); /*This line of Code added by me*/
eusartRxBuffer[eusartRxHead++] = u8Char;
/*sizeof(eusartRxBuffer) is 19 bytes*/
if(sizeof(eusartRxBuffer) <= eusartRxHead)
{
eusartRxHead = 0;
EUSART_Write('D'); /*This line of Code added by me*/
EUSART_DecodePadding(eusartRxBuffer); /*This line of Code added by me*/
EUSART_Write('E'); /*This line of Code added by me*/
}
else
{
EUSART_Write('G'); /*This line of Code added by me*/
}
EUSART_Write('O'); /*This line of Code added by me*/
eusartRxCount++;
} |
I have tried Clearing the Watchdog in USART ISR as mentioned bove in the code.
I have tried increasing the Watchdog expiry time to 256 seconds (i.e.., WDTCON = 0x12)
Still the issue persists...
Strange observations,
I have observed some strange things while transmitting the data over USART that when WDGT reset happens it seems like it is resetting the MCU immediately not after 256 seconds.
I am sure that its WDGT reset as because if I disable WDGT Init, reset doesn't occur...
I am adding an image for more details,
In the Image,
3 is the character sent from the tool and received the MCU.
GO -> represents the hit of ISR as mentioned in the above code.
DSEO -> represents Data handed over to handler, processed it, came back and exited the ISR. i.e, The task I need has successfully happened
R-> represents a Reset.
Kindly help me...
Additional Info if required:
MCC generated Code for USART init.....
Code C - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| void EUSART_Initialize(void)
{
// disable interrupts before changing states
PIE1bits.RCIE = 0;
// ABDOVF no_overflow; SCKP Non-Inverted; BRG16 16bit_generator; WUE disabled; ABDEN disabled;
BAUDCON = 0x08;
// SPEN enabled; RX9 8-bit; CREN enabled; ADDEN disabled; SREN disabled;
RCSTA = 0x90;
// TX9 8-bit; TX9D 0; SENDB sync_break_complete; TXEN enabled; SYNC asynchronous; BRGH hi_speed; CSRC slave;
TXSTA = 0x24;
// SP1BRGL 207;
SPBRGL = 0xCF;
// SP1BRGH 0;
SPBRGH = 0x00;
// initializing the driver state
eusartTxHead = 0;
eusartTxTail = 0;
eusartTxBufferRemaining = sizeof(eusartTxBuffer);
eusartRxHead = 0;
eusartRxTail = 0;
eusartRxCount = 0;
// enable receive interrupt
PIE1bits.RCIE = 1;
} |