I'm new to Silicon Labs and SPI communications, and I am wondering how I can read the chip ID of an ADXL362 accelerometer using an EFR32BG, and the 20 pin expansion header, using SPI. What kind of things do I need to do in order to set up the SPI Communication and successfully exchange messages between the board and the sensor?
I know that in the ADXL362, the device ID of the chip is stored in a register with address 0x00. Which function can i use from the spidrv.h library to read in the the register at that address?
Also, is it correct to initialise the SPI data like this?
SPIDRV_Init_t initData; initData.port = USART0; initData.portLocationTx = USART_ROUTELOC0_TXLOC_LOC19; //PD11 initData.portLocationRx = USART_ROUTELOC0_RXLOC_LOC19; // PD12 initData.portLocationClk = USART_ROUTELOC0_CLKLOC_LOC13; // PC10 initData.portLocationCs = USART_ROUTELOC0_CSLOC_LOC15; // PD10 initData.bitRate = 0; initData.frameLength = 8; initData.dummyTxValue = 0x55; initData.type = spidrvSlave; initData.bitOrder = spidrvBitOrderMsbFirst; initData.clockMode = spidrvClockMode0; initData.csControl = spidrvCsControlAuto; initData.slaveStartMode = spidrvSlaveStartImmediate; SPIDRV_HandleData_t handleData; SPIDRV_Handle_t handle = &handleData; SPIDRV_Init (handle, &initData);
Ok now I also know that i want to do the following things in the program
1. Set CS to 0 in order to read things.
2. Send 8 bits (0x0B) to the ADXL362, which will tell it that I want to read from the registers (MOSI).
3. Send an additional 8 bits (0x00) that specify that the address I want to read is the one that contains the device ID. (MOSI).
4. Read 8 bits from MISO pin, which should contain the device ID.
What functions will allow me to do the above? I have been looking at the documentation but it is not very clear. Thanks for whatever help you can give.
I suggest you read the source code of the driver. unfortunately I did not found an example code that use the spidrv driver. Not sure below link helps or not.
I saw the ADXL362 has some mode that need to configure, I don't know if you configure the ADXL362 correctly or not. You could try probe the SPI signals with an osciloscope to see if the signal was not as expected.
My views are my own and do not necessarily represent the views of Silicon Labs
And final update. I now have the 0x0B and 0x00 sending to the ADXL362. For some reason however, I am getting nothing but noise on the MISO channel. You can see this in the picture attached.
First waveform is CLK, second is CS, third is MOSI, and fourth is MISO. Just like on the ADXL362 datasheet, page 20, the MOSI channel is sending what it should. What could be a reason for the MISO being unresponsive?
Is your GND connection between the two OK? It is odd that MISO is 'around' instead of above GND.