====== Lab06 - Nucleo Communication stack ====== 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. ===== Recieve by Interupt ===== * In this session, we will receive data in an non-blocking manner using the interrupts uint8_t Rx_char[1]; void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { HAL_UART_Receive_IT(&huart2, Rx_char, 1); } int main(){ HAL_UART_Receive_IT (&huart2, Rx_char, 1); while (1) { } } * The function ''HAL_UART_RxCpltCallback'' is called every time that board receives a data from UART. The execution of this function does not stop while loop from going on. ===== The NUCLEO stack ===== * The NUCLEO side is expected to wait for the characters and add each received character to a stack. 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) { if (Rx_char[0] != prev_Rx_char[0]){ prev_Rx_char[0] = Rx_char[0]; oRecvBuff.chArrRecvBuff[oRecvBuff.iCnt] = (char) Rx_char[0]; oRecvBuff.iCnt++; HAL_UART_Transmit(&huart2, oRecvBuff.chArrRecvBuff , sizeof(oRecvBuff.chArrRecvBuff) ,10); HAL_UART_Transmit(&huart2, enter , sizeof(enter),10); } } * To see the complete project, download the files in link {{ :courses:be5b99cpl:labs:lab06_.zip |}}. ===== Exercise ===== * Define the mechanism of a "complete" command detection (based on '\r' and '\n'). * Define the mechanism of buffer clearing after successful processing of the received command. * Detect the "LED ON" and "LED OFF" commands to be able to control the User LED of the Nucleo board. * Detect the "BUTTON?" command to be able to read the User Button state.