Hi am trying to do bare metal programming using nRF52840 dk. I am working on UART protocol where I am trying to read a text file.
My text file look like this: It has 10 rows and 10 columns
81 116 104 104 121 90 125 110 127 105 80 116 104 104 121 44 125 110 127 100 ...... ......
I have implemented the following functions to read the byte
uint8_t get_char()
{
NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Enabled;
NRF_UART0->TASKS_STARTRX = 1UL;
while (!rxdrdy_ev) {
/* Put CPU to sleep and wake-up from interrupt */
__WFE();
__SEV();
__WFE();
}
rxdrdy_ev = false;
NRF_UART0->TASKS_STOPRX = 1UL;
NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Disabled;
return data;
}
The interrupt handler reads the byte when EVENTS_RXDRDY happens
volatile char data = '/0';
void UARTE0_UART0_IRQHandler()
{
if(NRF_UART0->EVENTS_RXDRDY == 1){
data = NRF_UART0->RXD;
NRF_UART0->EVENTS_RXDRDY = 0;
rxdrdy_ev = true;
}
}In the main file, I am storing the values into a 2d array.
float matrix[ROW_SIZE][COL_SIZE];
int i,j,n = 0, zero=(int)'0'; // helper when converting chars to integers;
uint8_t ch;
i = 0;
while(i < 10){
j = 0;
while(j < 10){
ch = get_char();
if(ch >='0' && ch <='9') n=10*n + (ch-zero);
else {
matrix[i][j] = n;
n=0;
}
j++;
}
i++;
}When I try to debug the code by sending a single character, I am able to receive it and store in the matrix array correctly. But when I send the whole text file serially using HTerm, I see garbage values in the matrix array. How to read the text file correctly.What am I doing wrong?