2019-10-01 06:46 AM
Can anyone post any code that can help me here please, or suggest me how to move forward
2019-10-01 06:50 AM
Use a scope, and check if the recorded wave forms / I2C bus sequences match those of the accelerometer datasheet / I2C bus section.
2019-10-01 07:01 AM
I am using SPI, yes it does match
2019-10-01 11:06 AM
anyone?
2019-10-02 07:06 AM
I suppose you can't read this registers directly. AFAIK, you need to write the desired register index first.
Check the datasheet.
2019-10-02 10:01 AM
in the following image the registers for x, y, z are enabled alreadyI
2019-10-03 12:34 AM
Enable means, the sensor generates sensible measurements that end up in this registers.
Reading them is a different matter, and not related to the control register.
Section 6.2 of the datasheet should tell you how it's done.
Access wide is 16 bits, and you have to give the R/W bit and the register address first, followed by data - or dummy data for a read.
Section 7 list the register addresses (offsets).
2019-10-03 01:35 AM
Hi @RNata.15 , in addition to @Ozone suggestions, please follow the indication regarding device power up configuration and axl data reading at p.13 of AN4662. Regards
2019-10-03 02:12 AM
The initial question is very superficial - it is not clear if all this is about a SPI sequence error (cannot read axis data registers at all) or data problem (data not as expected).
2019-10-03 06:49 AM
void spi_setup() //spi setup
{
CMU_ClockEnable(cmuClock_HFPER,true);
CMU_ClockEnable(cmuClock_GPIO,true);
CMU_ClockEnable(cmuClock_USART1,true);
GPIO_PinModeSet(gpioPortC,9,gpioModePushPull,1); //enabling he chip select
GPIO_PinModeSet(gpioPortC,6,gpioModePushPull,1); //MOSI
GPIO_PinModeSet(gpioPortC,7,gpioModeInput,0); //MISO
GPIO_PinModeSet(gpioPortC,8,gpioModePushPull,1); //CLK
USART_InitSync_TypeDef initdata = USART_INITSYNC_DEFAULT;
initdata.clockMode=usartClockMode3; //sample on rising edge
initdata.msbf=true;
initdata.autoCsEnable=true; //autochipselect enable is set
initdata.master=true;
initdata.baudrate=1000000;
initdata.enable=usartDisable;
USART_InitSync(USART1,&initdata);
USART1->ROUTELOC0 = (USART_ROUTELOC0_CLKLOC_LOC11)| //CLK
(USART_ROUTELOC0_CSLOC_LOC11)| //CS
(USART_ROUTELOC0_TXLOC_LOC11)| //mosi
(USART_ROUTELOC0_RXLOC_LOC11); //miso
USART1->ROUTEPEN = USART_ROUTEPEN_CLKPEN | USART_ROUTEPEN_CSPEN | USART_ROUTEPEN_TXPEN | USART_ROUTEPEN_RXPEN; //enabling
USART_Enable(USART1,usartEnable);
}
void spi_tx(uint8_t address, uint8_t data)
{
//GPIO_PinOutClear(gpioPortC,9); //pulling the chip select pin low
while(!(USART1->STATUS & USART_STATUS_TXBL)); //while this is not true, transmit buffer not empty
USART_Tx(USART1,address);
while(!(USART1->STATUS & USART_STATUS_RXDATAV)); //recieve buffer not empty, need to read, get out of while loop
USART_Rx(USART1);
while(!(USART1->STATUS & USART_STATUS_TXBL));
USART_Tx(USART1,data);
while(!(USART1->STATUS & USART_STATUS_RXDATAV));
USART_Rx(USART1);
//GPIO_PinOutSet(gpioPortC,9); //back to high
}
uint8_t spi_rx(uint8_t address)
{
//done so that READ bit is set as 1
//automatically enable the chip select
address = 0x80 | address;
while(!(USART1->STATUS & USART_STATUS_TXBL));
USART_TxDouble(USART1,address);
while(!(USART1->STATUS & USART_STATUS_RXDATAV));
USART_Rx(USART1);
while(!(USART1->STATUS & USART_STATUS_TXBL));
USART_Tx(USART1,0x00); //dummy
while(!(USART1->STATUS & USART_STATUS_RXDATAV));
//GPIO_PinOutSet(gpioPortC,9);
return USART_RxDouble(USART1);;
}
Hi,
Thank you for your patience and trying to help me out. The below image is of when I try to read from "who am i register" and I am getting the readings.
I did follow the steps as you said by writing the value to ctrl1 register and ctrl3.
but I am not able to get any values.
I am following the read and write bit as you told me.
Kindly help me out here please.
I have attached the code for reference