AnsweredAssumed Answered

uart with interrupt stm32L4

Question asked by semed abubakar on Mar 28, 2018
Latest reply on Mar 28, 2018 by Clive One

trying to set up a UART  receive with interrupt so far no success code is below im using stm32l4

any suggestions would be great thanks

 

#include "stm32l4xx.h"
#include "stm32l433xx.h"

char uart3_tx_data[]=" is here again";
void Init_USART3();
int indexx;
char usart3_rcv_buffer[20];

void USART3_IRQHandler()
{
Toogle_GPIOB_Pin(9);
if ((USART1->ISR & USART_ISR_RXNE) == USART_ISR_RXNE)
{
send_string(usart3_rcv_buffer);
usart3_rcv_buffer[indexx++] = (USART3->RDR); /* Receive data, clear flag */
}
}

int main (void)
{
RCC->APB1ENR1 |=(1<<4); //TIM6 clock enabled
TIM6->PSC = 0; // f timer = fclk / 24000 => 1kHz
TIM6->ARR = 0xFFf;
TIM6->CR1 = TIM_CR1_CEN;
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOBEN;
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOCEN;
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN;

GPIOC ->MODER &= ~ GPIO_MODER_MODE10_0;                        ///set GPIO2 as alternate functions
GPIOC ->MODER |= (GPIO_MODER_MODE10_1);
GPIOC ->OTYPER &= ~(GPIO_OTYPER_OT_10)                 ; ///push pull output type for GPIOA12
GPIOC ->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR10_0); // high speed for GPPIOC12
GPIOC ->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR10_1);
GPIOC ->PUPDR &= ~(GPIO_PUPDR_PUPDR10); //NO PULL UP*/

GPIOC ->MODER &= ~ GPIO_MODER_MODE11_0;                       ///set GPIO2 as alternate functions
GPIOC ->MODER |=(GPIO_MODER_MODE11_1);
GPIOC ->OTYPER &= ~(GPIO_OTYPER_OT_11); ///push pull output type for GPIOA12
GPIOC ->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR11_0); // high speed for GPPIOC12
GPIOC ->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR11_1);
GPIOC ->PUPDR &= ~(GPIO_PUPDR_PUPDR11); //NO PULL UP*/
GPIOC->AFR[1] |=(1<<28); //Alternate function 7 for PC10 USART TX
GPIOC->AFR[1] |=(1<<29);
GPIOC->AFR[1] |=(1<<30);
GPIOC->AFR[1] &=~(1<<31);

GPIOC->AFR[1] |=(1<<28); //Alternate function 7 for PC11 USART RX
GPIOC->AFR[1] |=(1<<29);
GPIOC->AFR[1] |=(1<<30);
GPIOC->AFR[1] &=~(1<<31);



Config_Lcd ();
Set_GPIOB_OutPut_No_Pu(9);

RCC->APB1ENR1 |= RCC_APB1ENR1_USART3EN; //enable USART3 clock
USART3->BRR =4000000/96; //baud rate = 9600
USART3->CR1&=~(1<<28); //1 Start bit, 8 data bits, n stop bits
USART3->CR1&=~(1<<12);
USART3->CR1 |= USART_CR1_UE; // USART3 enable.
USART3->CR1 |= (1<<3); // USART3 tx enable.
USART3->CR2 &= ~(1<<12); //1 stop bit
USART3->CR2 &= ~(1<<13); //1 stop bit
// USART3->CR1 = USART_CR1_RXNEIE | USART_CR1_RE | USART_CR1_UE;


char my_str[]="fooo";



__enable_irq(); //enable interrupt
NVIC_SetPriority(USART3_IRQn,4); //Set priority
NVIC_ClearPendingIRQ(USART3_IRQn); //clear pending
NVIC_EnableIRQ(USART3_IRQn);


while(1)
{

send_string(my_str); /* Will inititiate TC if TXE is set*/
USART3->RDR='a';
Delay_ms(1000);
Clear_Lcd();
Delay_ms(1000);
}

return 0;

}

Outcomes