2017-09-21 04:06 AM
Hi, I have a strange problem with ADC values reading. My MCU and ADC is configured like below:
My main.c is like below:
// Union with data from ADC
union { uint16_t ADCtable[9]; struct { uint16_t sensorsLine3Current; uint16_t sensorsLine4Current; uint16_t sensorsLine3Voltage; uint16_t sensorsLine4Voltage; uint16_t sensorsLine2Voltage; uint16_t sensorsLine1Voltage; uint16_t sensorsLine1Current; uint16_t sensorsLine2Current; uint16_t coreTempVoltage; }chanel;}ADCdata;int main(void) {
...
MX_DMA_Init();
MX_ADC_Init();
HAL_ADC_Stop_DMA(&hadc);
HAL_Delay(100); HAL_ADCEx_Calibration_Start(&hadc); HAL_Delay(100); HAL_ADC_Start_DMA(&hadc, (uint32_t*)&ADCdata.ADCtable[0], 9); // Start ADC with DMA HAL_Delay(100);while(1) {
...
}
}
I am reading this value and sending on UART like below:
void send_my_data(void) {
HAL_ADC_Stop_DMA(&hadc);
HAL_Delay(1000);
for(uint8_t i = 0; i < 9; i++) {
add_data_to_tx_host_buffer((ADCdata.ADCtable[i] >> 8) & 0xFF); add_data_to_tx_host_buffer(ADCdata.ADCtable[i] && 0xFF); } HAL_ADC_Start_DMA(&hadc, (uint32_t*)&ADCdata.ADCtable[0], 9); // Start ADC with DMAsend_to_host();
}
While reading ADCdata.ADCtable I am getting something like that on UART: ... 00 00 00 00 07 01 07 01 07 01 07 01 00 00 00 00 06 01 ...
it's mean:
ADCdata.ADCtable[0] = 0x0000 -> 0
ADCdata.ADCtable[1] = 0x0000 -> 0
ADCdata.ADCtable[2] = 0x0701 -> 1793
ADCdata.ADCtable[3] = 0x0701 -> 1793
ADCdata.ADCtable[4] = 0x0701 -> 1793
ADCdata.ADCtable[5] = 0x0701 -> 1793
ADCdata.ADCtable[6] = 0x0000 -> 0
ADCdata.ADCtable[7] = 0x0000 -> 0
ADCdata.ADCtable[8] = 0x0601 -> 1537
and in the same time (while HAL_Delay(1000); <- from send_my_data) I did printscr from VarViewer1:
And my question is:
What I am doing wrong ? How to read correct this data ?
Please help,
Dawid