Hi,
I wanted to capture data from this ADC with a custom sample rate, so I have set my STM32 timer to fire for example 12800 samples per second, and I have tied it's output to the start pin signal. Also I have connected the DRDY signal to one of external Pins of my MCU configured as an Interrupt on falling edges, when the interrupt fires, I just use the RDATA command to read the ADC data value, but the problem with this approach is that in some samples my data is zero, here is a screen shot of the captured data with matlab,
This is my main loop code
//Reset ADC
HAL_GPIO_WritePin(GPIOA,ADC_RST_Pin,GPIO_PIN_RESET);
HAL_Delay(1);
HAL_GPIO_WritePin(GPIOA,ADC_RST_Pin,GPIO_PIN_SET);
//Start ADC in continuous mode
HAL_GPIO_WritePin(GPIOA,ADC_START_Pin,GPIO_PIN_SET);
//Send SDATAC
tx[0]=0x11;
ADC_sendCommand(tx,rx,1);
tx[0]=0x43;//Wrtie config3 Reg
tx[1]=0x00;//Number of regs to write = 1
tx[2]=0xcc;//the value to be written
ADC_sendCommand(tx,rx,3);
//wait for internal Ref to power up
for(i=0;i<10000;i++);
//read reg to verify
tx[0]=0x23;//Read config3 Reg
tx[1]=0x00;//Number of regs to Read = 1
tx[2]=0x00;//
ADC_sendCommand(tx,rx,3);
tx[0]=0x41;//Wrtie config1 Reg
tx[1]=0x00;//Number of regs to write = 1
tx[2]=0xD2;//the value to be written //set sample clock to 16Ksps
ADC_sendCommand(tx,rx,3);
tx[0]=0x42;//Wrtie config2 Reg
tx[1]=0x00;//Number of regs to write = 1
tx[2]=0xF0;//the value to be written
ADC_sendCommand(tx,rx,3);
tx[0]=0x46;//Wrtie CH2 Reg
tx[1]=0x00;//Number of regs to write = 1
tx[2]=0x10;//the value to be written
ADC_sendCommand(tx,rx,3);
tx[0]=0x26;//Read CH2 Reg
tx[1]=0x00;//Number of regs to Read = 1
tx[2]=0x00;//
ADC_sendCommand(tx,rx,3);
tx[0]=0x44;//Write Fualt Reg
tx[1]=0x00;//Number of regs to Read = 1
tx[2]=0x00;//
ADC_sendCommand(tx,rx,3);
tx[0]=0x4D;//Write Unknown1 Reg
tx[1]=0x00;//Number of regs to Read = 1
tx[2]=0x00;//
ADC_sendCommand(tx,rx,3);
tx[0]=0x4E;//Write Unknown2 Reg
tx[1]=0x00;//Number of regs to Read = 1
tx[2]=0x00;//
ADC_sendCommand(tx,rx,3);
tx[0]=0x4F;//Write Unknown3 Reg
tx[1]=0x00;//Number of regs to Read = 1
tx[2]=0x00;//
ADC_sendCommand(tx,rx,3);
tx[0]=0x50;//Write Unknown4 Reg
tx[1]=0x00;//Number of regs to Read = 1
tx[2]=0x00;//
ADC_sendCommand(tx,rx,3);
tx[0]=0x51;//Write Unknown5 Reg
tx[1]=0x00;//Number of regs to Read = 1
tx[2]=0x00;//
ADC_sendCommand(tx,rx,3);
//Send SDATAC
tx[0]=0x11;
ADC_sendCommand(tx,rx,1);
//sample = 12800 and our time clock is 84MHz so set the time to 12800Hz
HAL_TIM_Base_Start_IT(&htim1);
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1);
TIM1->ARR=77;
TIM1->CCR1 = 39;
HAL_GPIO_WritePin(GPIOA,ADC_START_Pin,GPIO_PIN_RESET); // Start = 0
HAL_GPIO_WritePin(GPIOA,ADC_CS_Pin,GPIO_PIN_RESET);//CS = 0
ADC_ready=0;
Start_capture=0;
while (1)
{
if(Start_capture)
{
Start_capture=0;
HAL_GPIO_WritePin(GPIOA,ADC_START_Pin,GPIO_PIN_SET); // Start = 1
}
if(ADC_ready){
ADC_ready=0;
tx[0]=0x12; //RDATA Command
for(int g=1;g<28;g++)
{
tx[g]=0;
}
HAL_SPI_TransmitReceive(&hspi1,tx,rx,28,100);
HAL_GPIO_WritePin(GPIOA,ADC_START_Pin,GPIO_PIN_RESET); // Start = 0
adcBuf[i]=(rx[7] << 24) | (rx[8] << 16) | (rx[9]<<8) | 0x00;
adcBuf[i] /= 256;
}
}
Ans this is my External interrupt code
void EXTI3_IRQHandler(void)
{
/* USER CODE BEGIN EXTI3_IRQn 0 */
/* USER CODE END EXTI3_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
/* USER CODE BEGIN EXTI3_IRQn 1 */
ADC_ready=1;
/* USER CODE END EXTI3_IRQn 1 */
}
and here is my timer interrupt code
void TIM1_UP_TIM10_IRQHandler(void)
{
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */
/* USER CODE END TIM1_UP_TIM10_IRQn 0 */
HAL_TIM_IRQHandler(&htim1);
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 1 */
if(ADC_ready == 0)
{
Start_capture = 1;
}
/* USER CODE END TIM1_UP_TIM10_IRQn 1 */
}
So what's missing or am doing it wrong?