Hello,
After a lot of failure, I have decided to write my own SPI-read function.
The source is quite simple and it works!! but only one time :-( I think there is a problem with SPMF but I don't understand very well in the documentation:
------------------
SPMF is set after SPRF is 1 when the value in the receive data buffer matches the value in the M register.
To clear the flag, read SPMF when it is set and then write a 1 to it.
0 Value in the receive data buffer does not match the value in the M register
1 Value in the receive data buffer matches the value in the M register
--------------------
In fact the first time I read the adress 0x00 of the ADXL345, I get 0xe5 wich is ok, but after if I try to read an other adresses, I allways get 0xe5!!In fact it's impossible to write a new value in SPI0_D.
my code is:
------------------------------
uint8_t spi_read(uint8_t adresse)
{
uint8_t retour=0,dummy;
while(!(SPI_S_SPTEF_MASK & SPI0_S))
{ } //While buffer is not empty do nothing
SPI0_D =adresse+0x80; //write adress+0x80 (read mode)
while(!(SPI_S_SPRF_MASK & SPI0_S))
{ } //While received buffer is not full do nothing
retour=SPI0_D; //read the received value
| dummy=(SPI_S_SPMF_MASK & SPI0_S); |
| SPI0_S |= SPI_S_SPMF_MASK; | |
return retour;
}
---------------------------------------------
Thanks
Michel