Warning
This page is located in archive.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

courses:be5b99cpl:labs:lab07 [2018/10/04 15:47] (current)
Line 1: Line 1:
 +====== Lab07 - 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.
 +
 +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. ​
 +
 +{{ :​courses:​be5b99cpl:​labs:​rs232.png?​direct |}}
 +
 +===== The NUCLEO stack =====
 +The NUCLEO side is expected to wait for the characters in a pooling mode which will be implemented as:
 +<​code>​
 +void main( void )
 +{
 +  init();
 +
 +  while(1)
 +  {
 +    getCharacter();​
 +    insertCharacterIntoBuffer();​
 +  }
 +}
 +</​code>​
 +
 +The reception management of the characters requires a data structure which is implemented as:
 +
 +<code c>
 +#define cRECV_BUFF_MAX 10
 +typedef struct tRecvBuff
 +{
 +  char chArrRecvBuff[cRECV_BUFF_MAX];​
 +  int iCnt;
 +} tRecvBuff;
 +
 +tRecvBuff oRecvBuff;
 +</​code>​
 +
 +The structure is initialized as:
 +
 +<code c>
 +  oRecvBuff.chArrRecvBuff[0] = 0;
 +  oRecvBuff.iCnt = 0;  ​
 +</​code>​
 +
 +And the reception is performed through:
 +
 +<code c>
 + 
 +  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)  ​
 +</​code>​
 +
 +===== Exercise =====
 +  * Define and initialize necessary data structures to hold string commands sent over RS232 (such as "​*IDN?​\r\n"​).
 +  * 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 "​*IDN?"​ command and reply with a description of your "​device"​.
 +  * 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.
  
courses/be5b99cpl/labs/lab07.txt ยท Last modified: 2018/10/04 15:47 (external edit)