Hello people,
I am using Halcogen to generate the driver for spi. I am trying to communicate with a simple accelerometer ADXL345 (http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf ).
I have seen a lot example codes about spi communication in this forum, but still I am not able to communicate with this device. I will try to describe my configuration as detailed as possible. First of all, I use 4-wire SPI communication (SOMI, SIMO, CLK, CS[0]).
More specifically I generated the driver for SPI3, I set my charlen in Dataformat to 8 (as I want each transmission to be 8 bits, check clock polarity and clock phase in Halogen (required 1 and 1 by the accelerometer).
I generate the code and in code composer studio I just need to send one packet 0x00, that should return the Device ID as is mentioned in the manual of the device. So my main looks like this:
void main(void) { /* USER CODE BEGIN (3) */ uint16 TX_Data_Master[1] = { 0x00 }; uint16 RX_Data_Master[16] = { 0 }; uint32 counter=0; spiDAT1_t dataconfig1_t; dataconfig1_t.CS_HOLD = FALSE; dataconfig1_t.WDEL = TRUE; dataconfig1_t.DFSEL = SPI_FMT_0; dataconfig1_t.CSNR = 0xFE; spiInit(); while(1) { spiTransmitAndReceiveData(spiREG3, &dataconfig1_t, 1, TX_Data_Master, RX_Data_Master); }
I unfortunately receive 0x00F2 in my RX_Data_Master, which is not the expected. I am a bit confused about the blocksize parameter in the spiTransmitAndReceiveData function. Do you locate any other mistakes? My oscilloscope shows that the data that I transmit are ok, but at the same time shows a fluctuation in the receive line (SOMI). After the transmission the scope shows that the clock stops. Any tips or ideas?
(Forgive me for a potential dump explanation of my problem, but I am a begginer) :-)
Kind regards,
Stylianos Ganitis