cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 AD9833 SPI

shedili
Associate II
Posted on November 02, 2014 at 11:38

Hello,

I'm using an STM32F4 discovery board and I'm trying to control the DDS waveform generator chip AD9833 with it. I'm not very experienced with ARM. I have a AD9833 module like in the picture:

http://www.ebay.com/itm/like/281440408871

Datasheet of AD9833:

http://www.analog.com/static/imported-files/data_sheets/AD9833.pdf

Now, I happen to find a program that runs with Arduino, I've tested it and got no problem. I wanted to change that code so it is compatible with STM32F4. I used SPI tutorials and managed to get a successful compile but I do not see the desired signals on the oscilloscope. I used the PA5 and PA7 as the SPI pins for SCK and MOSI and PE3 for the FSYNC. Could you please help with this issue, I really appreciate it. I've put both the Arduino and my code on the zip file which can be downloaded:

https://drive.google.com/file/d/0B30BBdr7Hh3MZUlidG9JMmZrQzA/view?usp=sharing

Thank so much for the help!

#stm32f4 #discovery #spi
5 REPLIES 5
Posted on November 02, 2014 at 14:01

Probably want to be checking TXE/RXNE instead of blindly writing

/**
* @brief Write a byte on the SD.
* @param Data: byte to send.
* @retval None
*/
uint8_t SD_WriteByte(uint8_t Data)
{
/*!< Wait until the transmit buffer is empty */
while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET)
{
}
/*!< Send the byte */
SPI_I2S_SendData(SD_SPI, Data);
/*!< Wait to receive a byte*/
while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
{
}
/*!< Return the byte read from the SPI bus */
return SPI_I2S_ReceiveData(SD_SPI);
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
shedili
Associate II
Posted on November 03, 2014 at 17:34

Thanks for the help clive1. I have some questions though, if I'm not going to receive anything would i still have to use

while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
{
}
/*!< Return the byte read from the SPI bus */
return SPI_I2S_ReceiveData(SD_SPI);

part? Also how can i send the high part and low part of a 16 bit word in this method? Thanks.
Posted on November 03, 2014 at 19:08

It's important to understand the symmetrical nature of the SPI interface, TXE signals as soon as, and probably before, the first bit hits the wire,  whereas RXNE signals after the last bit has left. This is important with respect to manually driving as CS pin.

Do you have the interface in 16-bit mode? In which case the SPI->DR will be 16-bit wide. If in 8-bit mode you'll need to mask/shift the appropriate bits to match the byte endianess required by the devices.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
shedili
Associate II
Posted on November 23, 2014 at 13:51

Hello, I've been working on the project for a while now. I'm now able to generate the desired waveform but I can not set the frequency or the phase of the signal. Can you tell what am i doing wrong and how can it be fixed? Thank you very much!

https://drive.google.com/file/d/0B30BBdr7Hh3MaEhud0FLZS02TUU/view?usp=sharing

sulochana
Associate II
Posted on September 29, 2016 at 07:05

Hi,

I am using AD9833(DDS) waveform generator.Interfacing stm32 microcontroller and AD9833 Via SPI.

--My Question is ,How to generate waveform using AD9833 Chip.

--In AD9833 chip Frequency sweep is available.If available ,how to do frequency frequency sweep for every step of 1Hz.

I am very new to this please help me how to do this..Thank you.