cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f100rb uart reading or writing prblm

TARHAN SAMAH
Senior
Posted on October 23, 2017 at 10:42

hello , we re using stm32f100b ,we use  uart1 just for hyperterminal printf,

we use uart2 with interrupts of reading we try a simple prgm for write a frame of 16 bytes to uart2 and we connect rx2 to tx2 to read our own writing just for test now ,my interrupts work very good when i read from out a barcode reader for exemple. but when i connect my own tx2 i dont got any thing !!! i controlled every thing many times ...no data .my flag doesnt raise up?? i tried all three possibilities for rx2 pullup pull down nopull no changing

clck is 8mhz we use discovery cart and both of them 9600 baudrate 8 data no parity 2stop bits

in main:

__HAL_UART_DISABLE_IT(&huart2, UART_IT_PE); // parity error interrupt

 

__HAL_UART_ENABLE_IT(&huart2, UART_IT_ERR); //frame error interrupt

 

__HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);// Receive interrupt

because :   HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)  doesnt work at all !!!!! bloques the prgm ???

if(HAL_GPIO_ReadPin(GPIOA, BUTTON_Pin)==1)//USER BUTTON PUSHED sensd 16 bytes frames 

{

DATA_FRAME_GDT[0]=254;//0xFE

DATA_FRAME_GDT[1]=49;//1

DATA_FRAME_GDT[2]=53;//sdt 5

DATA_FRAME_GDT[3]=98;//'b'

DATA_FRAME_GDT[4]=49;//'1';

DATA_FRAME_GDT[5]=50;//'2';

DATA_FRAME_GDT[6]=51;//'3';

DATA_FRAME_GDT[7]=52;//'4';

DATA_FRAME_GDT[8]=53;//'5';

DATA_FRAME_GDT[9]=54;//'6';

DATA_FRAME_GDT[10]=55;//'7';

DATA_FRAME_GDT[11]=56;//'8';

DATA_FRAME_GDT[12]=57;//'9';

DATA_FRAME_GDT[13]=11;//number of data

DATA_FRAME_GDT[14]=7;//crc//942 mod 17

DATA_FRAME_GDT[15]=253;//0xFE

HAL_UART_Transmit(&huart1,DATA_FRAME_GDT,16, 0xFFFF);//for hyperterminal

HAL_UART_Transmit(&huart2,DATA_FRAME_GDT,16, 0xFFFF);//for gdt one blok sending 16 bytes at same time 

//for(i=0;i<16;i++)

//{

//HAL_UART_Transmit(&huart2,(uint8_t *)&DATA_FRAME_GDT[i],1, 0xFFFF);//for gdt sending byte by byte

//HAL_Delay(10);

//}

in the interrupt subroutine of file stm32fxx_it.c

void USART2_IRQHandler(void)

{

/* USER CODE BEGIN USART2_IRQn 0 */

/* USER CODE END USART2_IRQn 0 */

HAL_UART_IRQHandler(&huart2);

#define RXBUFFERSIZE 1

uint8_t aRxBuffer[RXBUFFERSIZE];

if (HAL_UART_Receive(&huart2, (uint8_t *)aRxBuffer, RXBUFFERSIZE,1) == HAL_OK)

{

barcode_store[barcode_char_num]= aRxBuffer[0];

barcode_char_num++;

if(aRxBuffer[0]==253)

{

barcode_collected=1;

barcode_char_num=0;

}

}

do you have any idea why i cannot read my own transmission????

2 REPLIES 2
TARHAN SAMAH
Senior
Posted on October 23, 2017 at 14:18

i solved some issue now i can use 

HAL_UART_Receive_IT(&huart2,aRxBuffer,1);

main:

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

if(huart--->Instance==USART2)

{

barcode_store[barcode_char_num]= aRxBuffer[0];

barcode_char_num++;

if(aRxBuffer[0]==10)

{

barcode_collected=1;

barcode_char_num=0;

}

HAL_UART_Receive_IT(&huart2,aRxBuffer,1);//activtae the interrupt every time

}

}

but stll can receiieve just barcode reader not from my own tx the sended of 16 bytes frame ???? very strange !!!

ali teke
Associate II
Posted on December 11, 2017 at 06:44

Hi Tarhan, 'HAL_UART_Receive' contains some loops inside of itself so i don't think it is the right place to use it in a 'IRQHandler' function. You had better to use it in main loop.