cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f103rct - mcu rs232 to 0x02 , 0x30 ,0x03 off / 0x02,0x31,0x03 on I don't know what the problem is. help me

Thon.1
Associate II

#define MAX_DATA_LENGTH 50

#define STX   0X02

#define ETX  0X03

u8 g_u8Rs232TxBuffer[105] = {0};

u16 g_u16Rs232Tick = 0;

extern UART_HandleTypeDef huart1;

//(0X02, 0X03 0X30 , 0X11~ 0X18) OFF 

//(0X02, 0X03 0X31 , 0X11~ 0X18) ON

u8 Rs232_DataReceived(u8 u8RxData[], u8 u8RxDataLength)

{

u8 u8Rdvalue = 0;  //ReceiveDataValue

u8 i=0;

u16 u16Temp =0;

if (u8RxData[0] )

u8Rdvalue = u8RxData[0];

}

void Fun_Uart1_RxReceived(u8 u8RxData)

{

static BOOL s_bDbgRxStartFlag = FALSE;

static u8 s_u8DbgBuffer[64] = {0};

static u8 s_u8DbgCount = 0;

int g_u8Dbg_RxBuffer[64] ={0};

if(s_bDbgRxStartFlag == TRUE)

{

s_u8DbgBuffer[s_u8DbgCount] = (u8)u8RxData;

s_u8DbgCount ++;

if(s_u8DbgCount >= 64)

{

s_u8DbgCount = 0;

s_bDbgRxStartFlag = FALSE;

}

else

{

if(u8RxData == 0x31)

{

s_bDbgRxStartFlag = FALSE;

}

}

}

else

{

if(u8RxData == 0x30)

{

s_bDbgRxStartFlag = TRUE;

s_u8DbgCount = 0;

}

}

}

void Rs232_SendData_(u8 Data)

{

huart1.Instance->DR = Data;

while(__HAL_UART_GET_FLAG(&huart1, UART_FLAG_TXE) == RESET);

}

8 REPLIES 8
Thon.1
Associate II

I made a separate c file

0x02 0x30 0x03

receive

Confirm and is true

Send

also 0x02 0x31 0x03 equal

Sorry, we don't even know what the question is.

You're rambling incoherently.

Perhaps you could start from the beginning?

You'd want to wait on TXE before sending data, not after.

You want to read some pattern/sequence and then respond?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

Receive (0x02 ,0x30 ,0x03)the data, check (0x02 ,0x30 ,0x03)the data and send it again if correct

Can you successfully receive any characters currently?

Probably the best approach would be to make a state-machine that progresses as you receive each successive character.

The USART IRQ Handler can fire for each character received.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

no recieve;..

to communicate with rs232

When 0x02,0x30,0x03, check the data value and if this data value is correct, send this value again and ask the program to display off.

stm32f103 and using cubemax.