External ADC Conversion with STM32F767  - Page 1
Forum section: electronics / general

author: A.Ersoz
author_rank: Regular Contributor
timestamp: August 29, 2019, 08:35:08 pm
content: Hello guys,I use external 12 bit ADC (ADS7886) on my custom PCB board. I try to get converted data from the ADC with SPI interface. But I couldn't get the converted value (I use debug mode of Keil to monitor, testdata_in variable). Does anyone have an idea to fix the problem?Code:uint8_t ADC_Write = 0x0; // Initial 4 bits are zerouint8_t ADC_Buf;//the variable below will hold the value in the buffer variable aboveuint16_t ADC_Buf_Val = 0;unsigned int testdata_in; // Converted data// ADC ConversionHAL_GPIO_WritePin(ADC_CS_GPIO_Port, ADC_CS_Pin, GPIO_PIN_RESET);HAL_SPI_Receive(&hspi4, ADC_Buf,2,100);ADC_Buf_Val = 0x0F & ADC_Buf; //get the lower 4 bits of the 8 most significant bitsADC_Buf_Val = ADC_Buf_Val << 8; //shift the bits to be in the upper 8 bits of the 16 bit variablesADC_Buf_Val += ADC_Buf; //get the lower 8 bits of the sampled valuetestdata_in = ADC_Write<<12 | ADC_Buf_Val;HAL_Delay(1);HAL_GPIO_WritePin(DAC_SYNC_GPIO_Port, DAC_SYNC_Pin, GPIO_PIN_SET);

author: thm_w
author_rank: Super Contributor
timestamp: August 29, 2019, 11:06:19 pm
content: Do you have a scope to see if your Sclk signal is going to the ADC at an appropriate frequency?Check the datasheet as well for timing on page 7, you might need some wait states. After CS for example.

author: lucazader
author_rank: Regular Contributor
timestamp: August 29, 2019, 11:30:51 pm
content: Let me start by saying:I am sure you have your reasons for selecting an external ADC and im more curious about your reasons.However using this ADC seems to be redundant?The F767 includes a 12-Bit SAR ADC that runs at up to 2.4MSPS.Are you using the external ADC as it is more accurate or linear than the on chip solution?As if this internal one was an option I would think it would be much easier to use. As well as causing less processor overhead, especially when used in DMA mode.Also reduces overall cost and complexity of the product.In response to your original question however:Like A.Ersoz mentioned. Check the SCK frequency. Usually it defaults to a div 2 (45MHZ from the 90mhz bus) but this chip has a max SPI clock frequency of 20MHz, so will probably need a higher prescaler value set in the spi config.

author: MasterT
author_rank: Frequent Contributor
timestamp: August 30, 2019, 01:05:07 am
content: I don't see initialization of the SPI:Code:/*##-1- Configure the SPI peripheral #######################################*//* Set the SPI parameters */SpiHandle.Instance = SPIx;SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;SpiHandle.Init.Direction = SPI_DIRECTION_2LINES;SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;SpiHandle.Init.FirstBit = SPI_FIRSTBIT_MSB;SpiHandle.Init.TIMode = SPI_TIMODE_DISABLE;SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;SpiHandle.Init.CRCPolynomial = 7;SpiHandle.Init.NSS = SPI_NSS_SOFT;#ifdef MASTER_BOARDSpiHandle.Init.Mode = SPI_MODE_MASTER;#elseSpiHandle.Init.Mode = SPI_MODE_SLAVE;#endif /* MASTER_BOARD */if(HAL_SPI_Init(&SpiHandle) != HAL_OK){/* Initialization Error */Error_Handler();}

author: Sal Ammoniac
author_rank: Super Contributor
timestamp: August 30, 2019, 01:53:16 am
content: Quote from: lucazader on August 29, 2019, 11:30:51 pmThe TI ADC has better specs than the built-in ADC for INL and DNL. Better SNR too.I've almost always found that an external ADC is less noisy than a built-in. The built-in ADC is on the same die as a CPU clocking away at >200 MHz and that's bound to have an effect!

author: A.Ersoz
author_rank: Regular Contributor
timestamp: August 30, 2019, 07:56:35 pm
content: Thank you guys for your responses!The reason for selecting external one is that same idea with Sal Ammoniac comment.For solving the problem, I configured the Baudrate with increasing prescaler value. Now the baudrate is 13.5 Mbit/s. Because the SCLK value should be 20MHz so, I tried to the baudrate not more the 20 MHz. The other thing is that I make it 10ms delay before SPI receiving data.Thanks again!Now, I try to visualize the converted data. Do you have any idea how I can visualize the converted signal?

author: thm_w
author_rank: Super Contributor
timestamp: August 30, 2019, 09:13:34 pm
content: Quote from: A.Ersoz on August 30, 2019, 07:56:35 pmDepends what you are looking for, visualize within the IDE? Which IDE are you using.Visual gdb has a feature "Live variables" for example:https://visualgdb.com/tutorials/arm/livevars/Data could also be sent over serial then plotted:https://arduino.stackexchange.com/questions/1180/serial-data-plotting-programsOr get a graphical LCD and plot it on there.

author: A.Ersoz
author_rank: Regular Contributor
timestamp: August 31, 2019, 08:49:47 pm
content: Maybe my question is missing. I want to make a simple interface to set the signal parameters and visualize the generated signals. Communication between the interface (PC) and the PCB will be bluetooth serial port.My IDE is Keil uVision 5.Do you have any idea or know any example with stm32?