2017-11-03 08:43 AM
Hi, I am using Keil and STM32F769I-Eval board.
I try to readout a sensor with an external ADC (AD7980). The signal I try to convert runs with 200kHz.
I generate with a timer every 5us an interrupt. With the interrupt I start the ADC and want to read back the values.
But after the end of the SPI transmission, there is a gap of 3.3us. This gap is to long. So I only get every second value.
yellow: SPI_CLOCK
green: GPIO_PIN_7
HAL_SPI_Receive(&hspi3, AD7980_RECEIVED ,2,1);
inter=0;
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_RESET);This is the code behind the scope above.
Is there a way to make this gap smaller?
I looked for a way to write my own routine to receive data. But I wasn't successful.
Kind Regards
Alex
2017-11-03 09:19 AM
>>
I looked for a way to write my own routine to receive data. But I wasn't successful.
You looked unsuccessfully, or wrote one and weren't more successful?
Did you try to use the registers and wait on SPI->SR.RXNE ?
Probably don't want to be using blocking code in the interrupt either.
2017-11-03 09:40 AM
uint8_t SPI3_send(uint8_t data)
{
uint32_t start_time_r; uint32_t this_time_r; SPI3->DR = data; // write data to be transmitted to the SPI data register while( !(SPI3->SR & SPI_FLAG_TXE) ); // wait until transmit complete while( !(SPI3->SR & SPI_FLAG_RXNE) ); // wait until receive complete while( SPI3->SR & SPI_FLAG_BSY) // wait until SPI is not busy anymore { this_time_r = HAL_GetTick() - start_time_r; if (this_time_r > 5000) { // timeout error! break; } return SPI3->DR; // return received data from SPI data register }}I tried this. But it doesn't work. It isn't sending any clock or datas.
When I debug the code, it never leaves the second while loop.
2017-11-03 10:25 AM
Use SPI 4 wire mode (16 clocks?)
If using a timer to make the conversion pulse at 200kHz, control the duty cycle to be right when the conversion is supposed to be completed. Then make an interrupt on that output compare falling edge event.
In the interrupt, read the SPI DR and back-it up in a buffer, then write on the SPI DR kick 16 bit SCK periods, no need to wait for its completion, the read will be done at next sample kick off.
This is a wild guess to make the interrupt as short as possible considering a pipeline flow of incoming data.
2017-11-05 04:15 AM
Did you init start time before entering the loop?
Start from a working spi example closest to your needs. Spi goes so fast we usually never need to wait in milisecond range. Don t use a so long delay under interrupt. It will cause more pain than cure to yout problem. What you need is a spi rxne interrupt.