Hi,
I am currently having trouble whith getting values of registers with SPITransfer.
I am using a CC3200-LAUNCHXL, and the sensor i am trying to use is an LSM9DS0.
I began from a code that was working, which used an other sensor (ADXL362). This code was adapted from the SPI demo, and was working well when trying to read/write the registers.
The only things i changed are adresses of the registers (obviously), and the protocol in the functions readSPI and WriteSPI, because they needed two bytes to give instructions (read/write+adress) for the ADXL instead of 1 for the LSM9DS0.
Unfortunately, i wasn't able to get the values of the registers anymore. When I looked at the signals with an oscilloscope, I saw that everything worked as it was supposed too, the instructions were given to the sensor and it answers the good values.
For example, I tried to read the WHO_AM_I register, and i saw the good value with the oscilloscope (0b01001001), but the value i get from SPITransfer in the code is 0b00000111.
The same problem occurs for every register.
Here are some parts of my code :
// // Reset SPI // MAP_SPIReset(GSPI_BASE); // // Configure SPI interface // MAP_SPIConfigSetExpClk(GSPI_BASE,MAP_PRCMPeripheralClockGet(PRCM_GSPI), SPI_IF_BIT_RATE,SPI_MODE_MASTER,SPI_SUB_MODE_0, (SPI_SW_CTRL_CS | SPI_4PIN_MODE | SPI_TURBO_OFF | SPI_CS_ACTIVELOW | SPI_WL_8)); // // Enable SPI for communication // MAP_SPIEnable(GSPI_BASE); unsigned char buffer; buffer=readSPI(LSM9DS0_REGISTER_WHO_AM_I_XM,XMTYPE);
And here is my function readSPI :
unsigned char readSPI(unsigned char OFFSET, unsigned int choix_capteur) { int iRetVal=1; unsigned char RESULT; unsigned char addr=(OFFSET|0x80)&0xBF; MAP_SPICSEnable(GSPI_BASE); int i=0; for (i=0;i<2000;i++){} iRetVal = iRetVal + MAP_SPITransfer(GSPI_BASE, &addr, 0, 1, 0);//write command for (i=0;i<2000;i++){} iRetVal = iRetVal + MAP_SPITransfer(GSPI_BASE, 0, &RESULT, 1, 0);//read command if (iRetVal<0){ Message("Erreur readSPI"); } else{ Report ("offset 0x%x (in readSPI) => 0x%x\n\r",OFFSET,RESULT); } MAP_SPICSDisable(GSPI_BASE); return RESULT; }
The parameter choix_capteur is not implemented yet, so it has no effect on the code. It will be useful later because the sensor has two SDO pins and two CS pins, each for a set of sensors.
I checked the hardware many times, so I guess the problem does not come from that ; and if yes, the oscilloscope would give me false values.
So,
- The sensor seems to work well, the signals are what they are supposed to be with the oscilloscope
- The values got with the function readSPI are wrong
Any piece of advice is appreciated :)
I guess i did not give all useful informations I could, so ask if you need some more.
Thank you for helping !