I am very new to STM32s. I have been trying to interface a sensor using an STM32F401RE Nucleo board but failing to receive sensor data from the board. I generate 3 clock signals to drive the sensor. I have programmed the board via CubeIDE and the program flashes onto the board without any problems. I confirmed (using a logic analyzer) that the code is generating the correct signals. I have the following configuration regarding connectivity:
- RCC -> HSE -> Crystal/Ceramic Resonator
- Connectivity -> USB_OTG_FS -> Device_Only
- Middleware -> USB_DEVICE -> Communication Device Class (Virtual Port Com)
- Clock Configuration -> 84 MHz
This video tutorial that I have been following has the same configuration. In fact, I have replicated each and every setting to match what the video shows. Basically there is a master clock signal, and two other signals which are interdependent. One of the interdependent signals triggers the internal ADC to read the sensor output via DMA (4th internal signal). Then the output of the ADC is programmed to be sent over USB to the host computer. When the person in the video opens a serial port reader (CoolTerm), he begins to see data showing up in the console without configuring anything (just pushes start). When I tried doing the same thing, using the same serial port reader, I don't see anything showing up in the console. I confirmed that I am using the right port. I tried varying the Baud Rates as well but no luck, not even garbage values. On a hardware level (as I mentioned earlier) I know that the signals are being generated. I am also able to detect and measure the output of the sensor using the Logic Analyzer. The only issue is not being able to get that data onto my computer.
I have been at this for weeks and cannot figure out why I cannot receive any data. I have initialized the components in the right order (DMA before the ADC). I have the right code in place, but unable to receive the output over USB.
I am used to developing on Arduino and Espressif boards so I was expecting something like a serial monitor to debug the board but apparently things are not so simple on STM.
Here is how I have declared the Buffer variable for holding the ADC data:
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
#define CCDBuffer 6000
volatile uint16_t CCDPixelBuffer[CCDBuffer];
/* USER CODE END 0 */
Here is how I have initialized and configured the Timers and ADC:
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_TIM3_Init();
MX_TIM4_Init();
MX_TIM2_Init();
MX_TIM5_Init();
MX_ADC1_Init();
MX_USB_DEVICE_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); // ICG Signal PA0
__HAL_TIM_SET_COUNTER(&htim2, 66);
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); // fM Signal PA6
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_4); // ADC Internal Signal
HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_2); // SH Signal PA1
/* USER CODE END 2 */
Here is how I am sending the ADC data over USB:
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_ADC_Start_DMA(&hadc1, (uint32_t*) CCDPixelBuffer, CCDBuffer);
}
/* USER CODE END 3 */
Here is the function definition for sending the ADC data over USB:
/* USER CODE BEGIN 4 */
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
CDC_Transmit_FS((uint8_t*) CCDPixelBuffer, CCDBuffer);
}
/* USER CODE END 4 */
Here is a screenshot of the Clock Configuration tab:
Here is a screenshot of the Pinout & Configuration tab:
I would be so grateful if anyone can please provide any insight as to why I am unable to receive data over USB from this Nucleo board. Thanks in advance for taking the time to read through.
#define CCDBuffer 6000
? \$\endgroup\$