2022-05-02 10:19 PM
Hi all iam working in stm32 f051c8tx microcontroller im trying to recieve a byte and if i recieve a byte in intrupt im printing "hello world " via tx of the same uart, the issue is im not able to recieve any char the below is the code any thoughts please let me know.
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
// HAL_UART_Transmit(&huart1, UART1_rxBuffer, 12, 100);
INTERUPT_RX_1 = rx_data[0];
HAL_UART_Receive_IT(&huart1, rx_data, 1);
}
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
memset(SSD1306_Buffer,0,strlen(SSD1306_Buffer));
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_I2C2_Init();
MX_SPI1_Init();
// MX_SPI2_Init();
MX_TIM2_Init();
MX_TIM3_Init();
MX_USART1_UART_Init();
MX_TIM6_Init();
MX_ADC_Init();
MX_TIM14_Init();
fsm_sens_init();
RetargetInit(&huart1);
sensor_init(&sensor_cfg);
HAL_UART_Receive_IT (&huart1, rx_data, 1);
while(1)
{
// printf("while \r\n");
if(INTERUPT_RX_1 != 0)
{
printf("while");
INTERUPT_RX_1 = 0;
}
}
}
static void MX_USART1_UART_Init(void)
{
/* USER CODE BEGIN USART1_Init 0 */
/* USER CODE END USART1_Init 0 */
/* USER CODE BEGIN USART1_Init 1 */
/* USER CODE END USART1_Init 1 */
huart1.Instance = USART1;
huart1.Init.BaudRate =19200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART1_Init 2 */
/* USER CODE END USART1_Init 2 */
}
2022-05-02 11:05 PM
Have you enabled the interrupt in NVIC?
Are the Rx pin set correctly in GPIO?
Read out and check/post content of USART and relevant GPIO and perhaps NVIC registers.
Some general interrupt-does-not-fire hints here.
JW
2022-05-04 04:06 AM
Hi Waclawek thanks for the reply
Have you enabled the interrupt in NVIC?
yes i have enabled the interrupt in Nvic
Are the Rx pin set correctly in GPIO?
yes it is correctly set in the gpio.
Thankyou for the reference
2022-05-05 08:34 AM
Probably not related to your problem, but this line isn't correct:
memset(SSD1306_Buffer,0,strlen(SSD1306_Buffer));
use sizeof() not strlen(). If the buffer is a global variable, it is likely already zero filled from the "C" startup code, and if so, strlen() will be zero. If the buffer is declared as a local variable in a function, it will contain uncertain data and strlen() may return a number much larger than the actual size of the buffer - them memset() will overwrite OTHER variables on the stack and bad things will happen.
2022-05-10 12:02 AM
thankyou i will change it
2022-05-10 12:07 AM
may i know how to enable the global interupts in the code by using code only not the cube ide code generation.
2022-05-10 01:30 AM
In Cortex-Mx, interrupts are enabled after reset globally.
To disable/enable interrupts globally, use
__disable_irq();
__enable_irq();
JW
2022-05-10 06:18 AM
Try this after UART Configuration:
__HAL_UART_ENABLE_IT(&huart1, UART_IT_RXNE);
2022-05-10 10:51 PM
Thankyou even i tried adding this even then the reception is not happening.
2022-05-10 10:52 PM
thankyou i enabled the global interrupts even then the interrupt driven reception is not working