Search
The communication between Nucleo board and PC uses RS232 data link. The C language allows you to use multiple levels of abstraction as it is described in the following figure. The operating system (OS) level uses open, write, read, close function and the C standard library uses fopen, fwrite, fread and fclose functions. While the C standard library provides the same behavior on the all platforms the OS level can vary with implementation.
The NUCLEO side uses direct access to the CPU registers with functions USART_ReceiveData and USART_SendData. These functions have two parameters: the first is a pointer to the memory location with USART peripheral and the second is the character to be sent and received.
The NUCLEO side is expected to wait for the characters in a pooling mode which will be implemented as:
void main( void ) { init(); while(1) { getCharacter(); insertCharacterIntoBuffer(); } }
The reception management of the characters requires a data structure which is implemented as:
#define cRECV_BUFF_MAX 10 typedef struct tRecvBuff { char chArrRecvBuff[cRECV_BUFF_MAX]; int iCnt; } tRecvBuff; tRecvBuff oRecvBuff;
The structure is initialized as:
oRecvBuff.chArrRecvBuff[0] = 0; oRecvBuff.iCnt = 0;
And the reception is performed through:
while(1) // Don't want to exit { uint16_t Data; while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET); // Wait for Char Data = USART_ReceiveData(USART2); // Collect Char oRecvBuff.chArrRecvBuff[ oRecvBuff.iCnt ] = (char)Data; oRecvBuff.iCnt++; -- check the overflow of the array !! cRECV_BUFF_MAX -- wait for the end of the command !! propose a proper ending of the command, e.g. '\r' and '\n' } // END while(1)