cancel
Showing results for 
Search instead for 
Did you mean: 

USART INTERRUPT STRING READ ISSUE

Don david
Associate II
Posted on March 06, 2017 at 14:21

Hi All,

I am working on STM32f103 CB and i am trying to read the RFID tag EM18 using USART1.Whenever the card is waved  on the Reader, i will receive a interrupt on USART receive pin PA10. Can anybody tell how to copy the received tag in the uart interrupt handler. I am able to copy only the first byte. i want to copy the entire 12 byte in the UART receive interrupt handler .

Below is my code snippet to read the RFID TAG

void USART1_IRQHandler(void)

{

    u8 i;

    char *t;

    RxBuffer[12] ='/0';

    

    {

  if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)

         

     

      /* Read one byte from the receive data register */

        for(i=0;i<12;i++)

        {    

      *t  = (USART_ReceiveData(USART1) & 0xFF);  

        

    RxBuffer[i] =*t++;    

        }

            

//        USART1_TX_Byte(RxBuffer[WriteDataCounter]);

        //Uart3Timeout = 10000;

        

    

        

    }

    

    USART_ClearITPendingBit(USART1, USART_IT_RXNE);    

}

 

Can anybody tell how to implement this

Kind Regards

Don

#usart-string-receive-interrupt #stm32f103cb-usart
6 REPLIES 6
Posted on March 06, 2017 at 15:15

The bytes arrive one at a time, copy each into a buffer, and advance the pointer. Don't sit in the IRQ Handler blocking execution.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal
Posted on March 06, 2017 at 15:21

Rename ' i ' into RX_Index; and make it a global variable (declared before the function, and as extern in the H file)

set RX_Index = 0;

Activate the RX interrupt

   Insider the interrupt, store in buffer indexed with RX_Index

   Then RX_Index++

   Then if RX_Index == 12 , disable the USART RX interrupts

In the main loop, wait for RX_Index ==12 to read the buffer.

Rinse and repeat for the next batch.

Posted on May 26, 2017 at 16:20

Hey guys,

I figured I'd jump in here as I have a related problem. I'm using USART3 on an STM32F1 with a serial terminal (RealTerm) and for some reason when I send data from the terminal my USART3_IRQHandler does not fire. I've got the TX side working fine (i.e. I can send data from USART3 to my serial terminal). I've checked my code several times and can't see anything wrong with it:

void USART3_Config(void)

{

GPIO_InitTypeDef GPIO_InitStruct;

NVIC_InitTypeDef NVIC_InitStructure;

USART_InitTypeDef USART_InitStruct;

// 1) Clock Config

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

// 2) GPIO Config

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10; // USART3 TX

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOB, &GPIO_InitStruct);

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11; // USART3 RX

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOB, &GPIO_InitStruct);

// 3) NVIC Config

NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQChannel;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

// 4) USART Struct Config

USART_InitStruct.USART_BaudRate = 9600;

USART_InitStruct.USART_StopBits = USART_StopBits_1;

USART_InitStruct.USART_WordLength = USART_WordLength_8b;

USART_InitStruct.USART_Parity = USART_Parity_No;

USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_Init(USART3, &USART_InitStruct);

// Enable RX interrupt

USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);

USART_Cmd(USART3, ENABLE);

}

...

void USART3_IRQHandler(void)

{

if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET){

// Read one byte from data register

RxBuffer[RxCounter++] = USART_ReceiveData(USART3);

if(RxCounter == 15){

// Disable interrupt

USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);

}

}

}

Can anyone help me with this? Have I missed something?

Cheers,

Tony

Posted on May 26, 2017 at 17:45

Does receive work in polling mode?

Try toggling a GPIO pin.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 26, 2017 at 20:37

Review vector table content, and linkage via .MAP file

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 29, 2017 at 18:21

Hi Clive,

I've tried polling for the data but still no joy. I also tried toggling the GPIO pin that I am using for USART3_RX (PB11) but it doesn't seem to have any effect.

I can see that USART3_IRQHandler is defined in both my vector table and my .MAP file...