2021-01-13 04:44 PM
Hi ST Community,
I am trying to Interface JPEG Camera to STM32F407 MCU via UART2 port.
My UART2 configurations:
char UART2_Config( void )
{
char u8UartReturn = SUCCESS;
USART_InitStructure.BaudRate = SERIAL_BAUDRATE_115200;
USART_InitStructure.WordLength = UART_WORDLENGTH_8B;
USART_InitStructure.StopBits = UART_STOPBITS_1;
USART_InitStructure.Parity = UART_PARITY_NONE;
USART_InitStructure.Mode = UART_MODE_RX ;
USART_InitStructure.HwFlowCtl = UART_HWCONTROL_NONE;
USART_InitStructure.OverSampling = UART_OVERSAMPLING_16;
GPRS_USART2_Init.Instance = USART2;
GPRS_USART2_Init.Init = USART_InitStructure;
GPRS_USART2_Init.Lock = HAL_UNLOCKED;
HAL_UART_Init(&GPRS_USART2_Init);
__HAL_UART_ENABLE_IT(&GPRS_USART2_Init,USART_IT_RXNE);
Cam_UART = GPRS_USART2_Init.Instance;
Cam_UART->SR &= ~USART_FLAG_RXNE;
Cam_UART->SR &= ~USART_FLAG_TC;
NVIC_ClearPendingIRQ(USART2_IRQn);
HAL_NVIC_SetPriority(USART2_IRQn,12,0);
NVIC_EnableIRQ(USART2_IRQn);
return u8UartReturn;
}
UART2_RxTx buffer:
typedef struct
{
char buff[MAX_SERIAL_BUFF_SIZE];
uint16_t count;
uint16_t buff_ptr;
uint8_t buff_status;
}UART_RxTx_Struct;
I am sending the reset command(in hex format) over UART to Camera. I did not receive any response from Camera.
IRQ Handler does not detect response from Camera over UART peripheral.(IRQ handler is not invoked at all).
I am adding the code snippets below:
sending Camera Reset Command to Camera:
{ uint8_t Reset_send[4]={0x56,0x0,0x26,0x0}; //Camera Reset
Mts_CAM_SendCommand(Reset_send,sizeof(Reset_send));
for(i=0;i<5;i++)
{
Dbg_Log("%x",USART2Rxstr.buff[i]);
}//checking response
if((USART2Rxstr.buff[0]==0x76) && (USART2Rxstr.buff[1]==0x0) && (USART2Rxstr.buff[2]==0x26) && (USART2Rxstr.buff[3]==0x0))
Dbg_Log("received Reset response");
}
// UART Transmit code for sending Bytes over UART2 TX
void Mts_CAM_SendCommand(char *cmd,int size)
{
unsigned char Count = RESET;
/* Clear the Rx buffer to receive next set of response. */
UART2_RxBuff_Flush();
/* Enable GPRS UART TX */
USART2->CR1 |= UART_MODE_TX;
HAL_Delay(10);
/* Send out commands through UART. */
for(Count = 0; Count < size; Count++)
{
USART2->DR= cmd[Count];
HAL_Delay(40);
}
}
//UART2 Interrupt handler - data is received via UART Interrupt and filled in UART_RxTx_Struct struct buffer and
// also written to Debug UART Port
UART_RxTx_Struct * UART2_Rx;
void USART2_IRQHandler (void)
{
volatile unsigned int IIR;
IIR = Cam_UART->SR;
NVIC_ClearPendingIRQ(USART2_IRQn);
Dbg_UART->DR = (uint8_t)'s'; //for debugging
Dbg_UART->CR1 |= (uint8_t)(UART_MODE_TX | UART_FLAG_TC);// for debugging
if (IIR & UART_FLAG_RXNE)
{
Cam_UART->SR &= ~UART_FLAG_RXNE;
UART2_Rx->buff[UART2_Rx->buff_ptr++] = (char)(Cam_UART->DR & 0x00FFU);
if(UART2_Rx->buff_ptr == MAX_SERIAL_BUFF_SIZE)
UART2_Rx->buff_ptr = RESET;
UART2_Rx->count++;
if(UART2_Rx->count == MAX_SERIAL_BUFF_SIZE)
UART2_Rx->count = MAX_SERIAL_BUFF_SIZE;
/* Print GPRS reply messages to UART debug window */
Dbg_UART->DR = (uint32_t)UART2_Rx->buff[UART2_Rx->buff_ptr -1 ];// for debugging
Dbg_UART->CR1 |= (uint32_t)(UART2_MODE_TX | UART_FLAG_TC);// for debugging
}
}
I have also debugged the hardware connections(Tx, Rx, gnd and Pwr pins) and everything on hardware side if fine.
NOTE: I have tested the camera with the same UART Configurations on PC using Cool term and able to send Commands in Hex format
and receive expected response from camera.
Thank you,
Regards,
Sai