Reply
Posts: 7
Registered: ‎10-02-2017

Simple UART0 print for EFR32 chip

Hi,

I generated a simple UART0 print for EFR32 chip - a bit of a noob to this chip.

The code was generated with hardware configurator.

It hangs in this after trying to send first byte:

 

void USART_Tx(USART_TypeDef *usart, uint8_t data)
{
  /* Check that transmit buffer is empty */
  while (!(usart->STATUS & USART_STATUS_TXBL))
    ;
  usart->TXDATA = (uint32_t)data;
}

 

Any ideas? Or is there sample code I can try from somewhere to get it going for EFR32BG1P233F256GM48 or a similar chip?

 

 

Posts: 581
Registered: ‎12-05-2016

Re: Simple UART0 print for EFR32 chip

Hi @Hypercube,

 

Is the UART hardware handshake being used and maybe preventing the character from being transmitted?

 

Some good examples for using some of the peripherals on the Wireless SoCs can be found with the Pearl Gecko (SLSTK3401A) examples.  The same core processor and peripherals are used in both products.  Even if one of those boards isn't available, the board number can be entered into the Solutions window and then selecting that board will show the various software examples for it, such as the SLSTK3401A_rs232 project.  For a lot of these projects they can be built for the Pearl Gecko and programmed to the radio board attached to the WSTK even though some warning will popup telling you that the parts are different.

 

I hope this helps.

 

Thank you,

jpitt

Highlighted
Posts: 7
Registered: ‎10-02-2017

Re: Simple UART0 print for EFR32 chip

Hi jpitt,

 

I had a lot of trouble for 3 days because no one seems bothered with creating important sample code from scratch using what is in the current IDE.

 

File > New Project > Silicon Labs App Builder Project > Bluetooth SDK > SoC Empty > set project name > in the dialog box select the part or chip (in my case EFR32BG1P233F256GM48) > click Finish
Project > Clean and compile - if see main return type is not int, then change the main line to the line below and compile again until there are no errors:

 int main(void)

Whilst the main.c file is selected on, click the debug icon, and program it to the device as is for checking that it all works.
Double click efr32bg1P233F256gM48.hwconf file
In the peripheral mapping window, scroll down to USART0 (don't mix it up with USAR1 next to it)
Enable RX and TX
Click on the problems tab and see 2 errors
Double click on "USART0_RX pin mode must be Input" and change the pin mode from Disabled to Input
Double click on "USART0_TX pin mode must be Push-pull" and change the pin mode from Disabled to Push-Pull, the click on Data Output and set it to 1 (Because default RS232 signal is 1 when idle)
In outline window double click on Peripherals > GPIO
Check USART0 and enable it - the default is 115200 baud N81 which is OK to use as is without modifications
On problems window, there is an error listed "USART0_CS pin is in use and must be enabled" - this can be ignored
Save the file and clean and recompile
Printing:

 #include "em_usart.h"
 #include <stdio.h>

 int Loopy;
 char msg[255];
 char *p;
 int i;

 int main(void){
 :
 :
 gecko_init(&config); // Insert print code after this line

 while(1) {
   Loopy++;
   for(i=Loopy; i<Loopy+2000; i++)  // this is just a delay function
     sprintf(msg,"Hi %i\n", Loopy);

   p = msg;
   while(*p != '\0')
     USART_Tx(USART0, *p++);
 }

 while (1) {  // Avoid running any code from this line onwards for the Bluetooth which blocks