你好,
We're attempting to communicate with an SPI based BMI055 Accelerometer ,
Here is our setup:
o P0_0 SPI Clock
o P0_1 LF_Enable (CS)
o P0_5 MISO
o P0_6 MOSI
And this is the code:
GPIO_ConfigurePin( GPIO_PORT_0, GPIO_PIN_0, OUTPUT, PID_SPI_CLK, false ); // Clock
GPIO_ConfigurePin( GPIO_PORT_0, GPIO_PIN_1, OUTPUT, PID_SPI_EN, true ); // CS
GPIO_ConfigurePin( GPIO_PORT_0, GPIO_PIN_5, INPUT, PID_SPI_DI, false ); // MISO
GPIO_ConfigurePin( GPIO_PORT_0, GPIO_PIN_6, OUTPUT, PID_SPI_DO, false ); // MOSI
// …
spi_init(&cs_pad_param, // Note: This point to the pin and port of the CS line
SPI_MODE_8BIT,
SPI_ROLE_MASTER,
SPI_CLK_IDLE_POL_LOW,
SPI_PHA_MODE_1,
SPI_MINT_DISABLE,
SPI_XTAL_DIV_8);
And a simple read register code:
spi_cs_high();
spi_set_bitmode(SPI_MODE_8BIT);
spi_access((uint8_t)(READ_MODE|address));
regval = (uint8_t)spi_access(0x0000); // Note : regval is always 0xff
spi_cs_low();
Now, the read attempt always returns 0xff (the value at address 0x50001202),
We know for sure that this is wrong as we are attempt to read a default value which should be 0xFA .
Thank you,
Baswaraj
嗨Baswaraj,
Usually SPI CS is active low, so you should go low first then go high. Not the other way around. Maybe you try that?
Other than that, if you have an oscilloscope, you should observe the SPI bus. Good luck.
Edit: Good to "exercise" the CS pins by quickly toggling low then high and keep high there before your actual reading.