The Thunderboard Forum is no longer active. If you would like to post a question regarding Thunderboard Kits, please use the Bluetooth Forum.

This discussion and its replies are closed

Hi,

I'm using the Thunderboard BG22 and I have some problem to receive data with the UART, I can just receive 2 characters as shown in picture below :

 

so in com7 there is the string that I need to receive but I could just receive the 2 first 2 characters of it,

I was thinking if I need to add a delay, but I don't know how

This is the code that I use


void sendData(USART_TypeDef *usart, uint8_t data[]){
	int i;
	for (i = 0; i <strlen(data) ; i++){
		USART_Tx(usart, data[i]);
	}
	USART_Tx(USART1, '\r');
}

static volatile char recv[10];
static volatile char C;


int main(void)
{
  uint32_t i;

  // Chip errata
  CHIP_Init();

  // Initialize GPIO and USART1
  initCmu();
  initGpio();
  initUsart1();
  USART_BaudrateAsyncSet(USART1,0,9600,usartOVS16);

  int j;
  while (1)
  {
	  uint8_t buff[8] = "AT$I=10\r";
	  sendData(USART1, buff);
	  for (j = 0 ; j < 10 ; j++){
	  			  C = USART_Rx(USART1);
	  			  if (C != '\r')
	  				recv[j] = C;
	  }
  }
}

 

  • Discussion Forums
  • Thunderboard Kits
  • Answered
Answered
  • It's not really a Thunderboard question, your buff declaration is too short and it should include a null byte if you want to use strlen to determine the length.

    You also will probably get warnings on types/signs.

    Try this line instead:

     uint8_t buff[] = "AT$I=10\r\0";
    
    0
  • Dear Nabil,

    As mentioned above, you should rather use uint8_t buff[], because you will check the length anyway in the send function with strlen, not with a constant.
    The '\0' part is not needed, because the quotation marks do this automatically.

    It is not a good practice to wait for the characters with blocking, you should either use async interrupt or polling.
    The USART_STATUS_RXDATAV bit will show, if you recieve valid data via RX.

    With one of the suggested method the transfer should work fine.

    Hope it helps, and if you have any question just let me know.

    Regards,
    Adam

     

    1
  • The USART_STATUS_RXDATAV  is already checked by the USART_RX fonction :

     

    uint8_t USART_Rx(USART_TypeDef *usart)
    {
    	int i = 0;
        while ((!(usart->STATUS) & (USART_STATUS_RXDATAV)) && (i < 30)) {
    	  i++;
      }
      return (uint8_t)usart->RXDATA;
    }

     

    0
  • I just checked the USART_STATUS_RXDATAV  bit I don't understand why what I receive is 10('\n')

                                                

    0
  • Hy Nabil,

    Which one did you used? Polling or interrupt?

    Did you set the baudrate in PUTTY to 115200? Because in the examples above, it sets the clock to this value.

    As i can see the RX function was modified from the original from the em_usart.h file.
    It should look like this:

    uint8_t USART_Rx(USART_TypeDef *usart)
    {
       while (!(usart->STATUS & USART_STATUS_RXDATAV))
       ;
    
     return (uint8_t)usart->RXDATA;
    }

    Use the 30 constant from the modified RX function in the main's for cycle, if using polling (#define BUFLEN 30).
    I suggest to use a new empty example and write the modification in the main function.

    Let me know if it still doesn't work.

    Regards,
    Adam

    0
  • Hi Adam,

    Thanks for your remply,

    I just tried the Polling example, I didn't change anything, like copy and past from the github link that you gived me, but it still doesn't work, I have everythime the same problem I can only read 2 characters,

    I used 115200 for the bauderate as demanded for EFR32BG22, and I could see the 2 characters(no more than 2 characters) that I received in Putty's terminal.

    best regards,

    Nabil.

    0