cancel
Showing results for 
Search instead for 
Did you mean: 

SPI communication with AD9959 4 channel MSPS DDS analog device

Vueko
Associate III

Hi, I'am currently working on implementing a driver with the AD9959 with the stm32G474re discovery board, I am able to write to all 4 channel to generate any frequencies with any phases with the SPI module, but when I'm trying to read, HAL_SPI_Receive() gives back a receive buffer with zeros values, I don't understand why, is there anyone who is working on some analog device product and encoutered a similar problem, I'm using spi3 on full-duplex master mode, I probe my sck, MISO and MOSI signal, I can see that the MOSI signal have a correct behaviour, but the MISO signal nevet gets updated even though I programed the device to go on single bit 3 wire mode. Insted, the MOSI signal is changing. At first, I though that my write function was wrong, but it doesnt seems to be the case since I can disable the selected channel, and program any frequencies for each channel by having programmed the 3 wire mode, if it's not on 3 wire mode the code don't work anymore. Here is my write and read function. In the read function, the AD9959_SPI_Transfer() function is calling HAL_SPI_Transmit() to send the read byte instruction. In the read function, the received buffer, receidata is always 0.

Any help would be gladly appreciated!

 

void AD9959_Write(AD9959_Handler *device, AD9959_REG_ADDR reg_addr,  uint32_t data) //incomplete
{
/* Determining which register is accessed */
uint8_t instruction = WRITE_INST | (reg_addr & 0x1f);
 
HAL_GPIO_WritePin(device->cs_port,device->cs_pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(device->SPI_Hanlder, &instruction, sizeof(instruction),HAL_MAX_DELAY);
 
/* writing the value */
/* Finding the length of the current register to update */
 
 
uint8_t i,transfer_data[4];
uint8_t len = registers[reg_addr].size;
//MSB first
i = 0;
while(len-- >0){
*(transfer_data + i) = (data >> len*8) & 0xFF;
i++;
}
HAL_SPI_Transmit(device->SPI_Hanlder,transfer_data,i,HAL_MAX_DELAY);
HAL_GPIO_WritePin(device->cs_port,device->cs_pin, GPIO_PIN_SET);
// Update device
 
//AD9959_Update(device);
}
 
uint32_t AD9959_Read(AD9959_Handler *device, AD9959_REG_ADDR reg_addr) //***ed
{
uint8_t read_instruction = READ_INST | (reg_addr & 0x1F);
 
uint8_t receivdata;
HAL_GPIO_WritePin(device->cs_port, device->cs_pin, GPIO_PIN_RESET);
 
uint8_t len = registers[reg_addr].size;
 
AD9959_SPI_Transfer(device, &read_instruction, sizeof(read_instruction));
HAL_Delay(1);
HAL_SPI_Receive(device->SPI_Handler, &receivdata, len, HAL_MAX_DELAY);
 
 
HAL_GPIO_WritePin(device->cs_port, device->cs_pin, GPIO_PIN_SET);
 
return receivdata;
}
3 REPLIES 3
Vueko
Associate III

Update, I manage to get a response to the MISO line but it is not updated to my receivdata variable for some reason

It's only one byte wide, if len > 1 it needs to be bigger.

Perhaps try the Transmit / Receive form?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

Hi, I tried the Transmit/Receive form and well, the Miso line gets updated but my received buffer in the HAL_SPI_TransmitReceive() is always 0