HiFive1 SPI Question?


(cailinlin) #1

I want to read/write sensor data for SPI interface.

When I read/write on HiFive1 using Arduino, the result is correct.
But When I use FreedomStudio, the value of the register always lacks the least significant bit. For example, it should be 0xf, which is actually 0x7; it should be 0x5, which is actually 0x2;

My configuration of SPI as follow:

GPIO_REG(GPIO_IOF_SEL) &= ~IOF0_SPI1_MASK;
GPIO_REG(GPIO_IOF_EN)  |=  IOF0_SPI1_MASK;
SPI1_REG(SPI_REG_SCKMODE) = SPI_MODE0;
SPI1_REG(SPI_REG_FMT) = SPI_FMT_PROTO(SPI_PROTO_S) |
						SPI_FMT_ENDIAN(SPI_ENDIAN_MSB) |
						SPI_FMT_DIR(SPI_DIR_RX) |
						SPI_FMT_LEN(8);

I reference sifive/cinco/blob/master/hardware/freedom_e/libraries/SPI/src/SPI.cpp


(Wesley W. Terpstra) #2

This sounds like you slipped a bit. My guess is that theSPI clock frequency is too high on the FreedomStudio version. Try reducing the clock rate to a half and see if that fixes it.


(cailinlin) #3

Thanks! The problem was solved.
You are right, it is caused by high clock freqeuncy.
It can work when I Configure the SPI Serial Clock Divisor Register.