Reply
Highlighted
Posts: 19
Registered: ‎10-13-2016
Accepted Solution

BGM111 and SPI problems in C

Hi,

 

Im learning how to make a project with the BGM111 in C,

 

At this moment im modifing the project soc-thermometer to have the communication with I2C and SPI and also debug the information in the UART.

 

At this moment the UART works fine and also the I2C, i modified and i can see the temperature and humidity parameters, but i have been trying to communicate to the Accelerometer BMA280 taking the code of example here:

 

http://community.silabs.com/t5/Bluetooth-Wi-Fi/Using-accelerometer-in-BGM111-BMG113-dev-kit-with-C-S...

 

But i dont see any signals with a logic analizer. Is not doing anything, what im doing is in my main program i initialize the spi:

 

spi_init();

 

and then i just read the LSB of X with this BMA280_RegisterRead(USART0,0x02);

 

So my questions are:

 

1.- Im i missing something here in the configuration or am i doing something wrong?

 

2.- Does it affect that im using the UART communication to debug in the computer? im using the printf and added RETARGET_VCOM=1 to my project

 

 

 

Posts: 2,582
Registered: ‎09-01-2015

Re: BGM111 and SPI problems in C

The problem is most likely that printf uses USART0 (in UART mode) and the sample SPI code in the link that you provided uses USART0 for SPI communication.

 

An easy fix would be to convert the SPI code to use USART1 instead of USART0. To do this, it should be enough to just replace USART0 with USART1 in the init code and then also change the pin location settings (ROUTELOC0 register ) that is set at the end of spi_init() function. You need to check the correct locations from EFR32BG1 datasheet.

 

 

 

Posts: 19
Registered: ‎10-13-2016

Re: BGM111 and SPI problems in C

I have tried that before also but when i do the moment it tries to communicate by spi all the code gets blocked, it doesnt transmit to the terminal. as far as i understand the documentation you are refering to in the page 140

 

https://www.silabs.com/documents/login/data-sheets/efr32bg1-datasheet.pdf

 

Says that the location of those 4 pins in US1 is also loc11 same as usart0 so in theory the instruction should be:

 

USART1->ROUTELOC0 = USART_ROUTELOC0_CLKLOC_LOC11 | USART_ROUTELOC0_TXLOC_LOC11 | USART_ROUTELOC0_RXLOC_LOC11 | USART_ROUTELOC0_CSLOC_LOC11;

 

 

Posts: 2,582
Registered: ‎09-01-2015

Re: BGM111 and SPI problems in C

Did you also enable clock for usart1? 

 CMU_ClockEnable(cmuClock_USART1, true);
Posts: 19
Registered: ‎10-13-2016

Re: BGM111 and SPI problems in C

Yes this is what i have:

 

void spi_init()
{
  // EMLIB documentation online:
  // http://devtools.silabs.com/dl/documentation/doxygen/4.3.0/efr32bg1/html/group__emlib.html

  // PIN PC9 = SPI_CS
  GPIO_PinModeSet(gpioPortC, 9, gpioModePushPull, 1);

  // PIN PC8 = SPI_SCK
  GPIO_PinModeSet(gpioPortC, 8, gpioModePushPull, 1);

  // PIN PC7 = SPI_MISO
  GPIO_PinModeSet(gpioPortC, 7, gpioModeInput, 0);

  // PIN PC6 = SPI_MOSI
  GPIO_PinModeSet(gpioPortC, 6, gpioModePushPull, 1);


  USART_InitSync_TypeDef config = USART_INITSYNC_DEFAULT;

  CMU_ClockEnable(cmuClock_HFPER, true);		// Enable HF peripheral clock
  CMU_ClockEnable(cmuClock_USART1, true);
  CMU_ClockEnable(cmuClock_GPIO, true);

  config.enable = usartDisable;
  config.baudrate = 100000; /* 100 kbits/s. */
  config.clockMode = usartClockMode3;   /* Clock idle high, sample on rising edge. */
  config.msbf = true; /* Send most significant bit first. */

  config.autoCsEnable = true;
  USART_InitSync(USART1, &config);

  USART1->ROUTELOC0 = USART_ROUTELOC0_CLKLOC_LOC11 | USART_ROUTELOC0_TXLOC_LOC11 | USART_ROUTELOC0_RXLOC_LOC11 | USART_ROUTELOC0_CSLOC_LOC11;
  USART1->ROUTEPEN = USART_ROUTEPEN_CLKPEN | USART_ROUTEPEN_TXPEN | USART_ROUTEPEN_RXPEN | USART_ROUTEPEN_CSPEN;

  USART_Enable(USART1, usartEnable);

}

and then in the main i just call spi_init();

 

and then BMA280_RegisterRead(USART1, 0x02); To get the LSB value of the X axel

Posts: 2,582
Registered: ‎09-01-2015

Re: BGM111 and SPI problems in C

I tested your code and got it to work when I put it after the call to 

enter_DefaultMode_from_RESET()

 

If it is right in the beginning of main() then it does not work. There must be some initialization that is missing and it is done in enter_DefaultMode_from_RESET().

Posts: 19
Registered: ‎10-13-2016

Re: BGM111 and SPI problems in C

I think that was the problem im getting some data, now i just need to check if everything looks correct.

 

Thank you for your support as always very helpful