Im currently trying to interface my STM32F4 discovery board with a silicon sensing CRG20 gyro Datasheet
Normally they output a 6 byte packet but all I am receiving is a 1 byte with 2 bits set (same ones each time) and 5 bytes of 0. I have tested that the SPI reading is working be connecting the MOSI and MISO pins on the discovery board and getting the same input as output.
I have based my code off the tutorial for the board and I dont have a logic analyser to check what is happing
Can anyone give me some advice on how to get this to work? Any help would be greatly appreciated
spi config:
Code: Select all
static const SPIConfig spicfg = {
spicb,
/* HW dependent part.*/
GPIOB,
12,
0
| SPI_CR1_CPHA
| SPI_CR1_MSTR
| SPI_CR1_BR_1
| SPI_CR1_SPE //Enable SPI
};SPI initialisation:
Code: Select all
spiStart(&SPID2, &spicfg);
palSetPad(GPIOB, 12);
palSetPadMode(GPIOB, 12, PAL_MODE_OUTPUT_PUSHPULL |
PAL_STM32_OSPEED_HIGHEST); /* NSS. */
palSetPadMode(GPIOB, 13, PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* SCK. */
palSetPadMode(GPIOB, 14, PAL_MODE_ALTERNATE(5)); /* MISO. */
palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* MOSI. */
Reading from SPI
Code: Select all
int gyroReq[6]={3,0,0,0,0,252};
spiSelect(&SPID2);
for(i=0;i<6;i++){
tempOut[0]=gyroReq[i];
spiExchange(&SPID2,1,tempOut,tempIn);
buf[i]=tempIn[0];
}
spiUnselect(&SPID2);I did try doing the spiExchange with all 6 bytes but it didnt seem to work to I opted to do it byte by byte (although I would prefer to do it all with one line of code