2023-11-30 08:51 AM
Hi, I am working on SPI to communicate with the AD9959 from analog device, I'm analyzing the MOSI and MISO signal with probes on an oscilloscope and can see that I can successfully write and read from the device, the thing is that HAL_SPI_Receive() send back the received buffer pRxData with the value 0 instead of the value from the MISO line, is there a reason for that ? I'm pretty sure I respect the specification of the spi communication for the device. In my case i set it on spi single-bit 3 wire mode to use MOSI and MISO lines, and on my spi parameters, I'm in spi mode 0 as it should by looking at the datasheet.
I dragged the datasheet below for those who are interested with the code of my read function. The variable which is suppose to hold the value returned by the slave (AD9959) in the MISO line (receivdata) is always 0 but the MISO line returned the value that have been written to the register.
Thank you for your time.
2023-11-30 11:19 AM
> spi single-bit 3 wire mode to use MOSI and MISO lines
MISO is connected to SDIO_2? Recheck your pin assignments. Perhaps share a schematic.
2023-12-01 05:25 AM
Hi @TDK yes MISO is connected to SDIO_2 as MOSI is to SDIO_0, SDIO_3 is grounded and SDIO_1 is keep at float, I'm 100% sure of my connections here is a schematic of the AD9959 from the user guide, you'll find it at the end of the documents. I can share a picture of my SPI configuration
2023-12-01 06:55 AM
> val |= (*(receivdata + i) >> len*8) & 0xFF;
How are you confirming that the data coming back is 0? Looks like your code will set val=0 regardless of the data in receivdata. len*8 is presumably at least 8. shift a uin8_t to the right by 8 or more bits and you get a 0. At minimum, this is a bug.
2023-12-01 07:37 AM
In my main.c i use the function like this
readval = AD9959_Read();
the value is always 0 even after changing > val |= (*(receivdata + i) >> len*8) & 0xFF to > val |= (*(receivdata + i) << len*8) & 0xFF
so i assume receivdata is always 0
2023-12-01 08:15 AM
That code still has bugs.
Maybe debug that separately from the SPI issue. Give receivdata correct values, step through your loop, and watch val update. You will see the error.