Skip to main content
Thon.1
Associate II
Dec 23, 2019 12:20 AM UTC
Question

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

#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);

}

This topic has been closed for replies.

8 replies

Thon.1
Thon.1Author
Associate II
Dec 23, 2019 12:21 AM UTC

I made a separate c file

Thon.1
Thon.1Author
Associate II
Dec 23, 2019 12:24 AM UTC

0x02 0x30 0x03

receive

Confirm and is true

Send

Thon.1
Thon.1Author
Associate II
Dec 23, 2019 12:35 AM UTC

also 0x02 0x31 0x03 equal

Tesla DeLorean
Guru
Dec 23, 2019 12:40 AM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Thon.1
Thon.1Author
Associate II
Dec 23, 2019 1:08 AM UTC

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

​

Tesla DeLorean
Guru
Dec 23, 2019 1:42 AM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..