cancel
Showing results for 
Search instead for 
Did you mean: 

spi sending data adress issues

d4ng3r09
Associate II
Posted on September 02, 2014 at 19:14

Hi guys ,

i am trying to figure out how to get stm32f4 discovery board accelerometer work. After checking the lisd302dl datasheet and reference manual (that wasn't too much helpful) ,i went to forum where i find the example in this

/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/STM32F4%20Discovery%20Accelerometer%20SPI%20Problem&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=2921

. Could somebody explain to us (obviously i am not the only one who asked about that) why and where did we find the adress to send on the spi (

0xAB00,

0x20C7)

? I am asking since i didn t find anything in both previous references. Thank you for your attention

int
main(
void
)
{
SystemInit();
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOE , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
//Init SPI-Pins
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//Init CS-Pin
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_SetBits(GPIOE, GPIO_Pin_3); 
//Set CS high
GPIO_PinAFConfig (GPIOA, GPIO_PinSource5 |GPIO_PinSource6 |GPIO_PinSource7 , GPIO_AF_SPI1);
SPI_I2S_DeInit(SPI1);
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master ;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b ;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High ;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft ;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 0;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);
GPIO_ResetBits(GPIOE, GPIO_Pin_3);
SPI_I2S_SendData(SPI1, 0x20C7); 
//Sensor Config
while
(1){
//Read Y-Axis
SPI_I2S_SendData(SPI1, 0xAB00);
SPI_I2S_ReceiveData(SPI1);
}

#rtfm
3 REPLIES 3
Posted on September 02, 2014 at 22:03

I guess you could look at the bit waveforms described in the

http://www.st.com/web/en/resource/technical/document/datasheet/CD00135460.pdf

, and review the register bit settings.

0x20C7 - Write value 0xC7 into register 0x20 (CTRL_REG1)

0xAB00 - Read value from register 0x2B (OUT_Y)

0x00 (WRITE) + 0x20 (CTRL_REG1) = 0x20

0x80 (READ) + 0x2B (OUT_Y) = 0xAB

The high order byte is the Command, and Read/Write direction, the low order byte is the value to Write if sending data to a register.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
d4ng3r09
Associate II
Posted on September 03, 2014 at 11:42

I still don t get it neither can find it : why do we need to write 0xc7 in CTRL_REG1?

Is also 0x80 +register adress a normalisation for receiving data in spi?

Posted on September 03, 2014 at 16:34

You're going to need to get a lot sharper if you plan on doing this as a career.

0xC7 because I guess you want the device powered up, output high-rate measurements, and want the X, Y & Z channels enabled?

0690X00000603I8QAI.jpg

0690X0000060Mo9QAE.gif

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..