参考官方例程做usart多机通信,它是怎么样发送地址的?
只看到 USART_SendData(USARTy, 0x33);那地址怎么发送了的?
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
/* System Clocks Configuration */
RCC_Configuration();
/* Configure the GPIO ports */
GPIO_Configuration();
/* Initialize Leds, Wakeup and Key Buttons mounted on STM3210X-EVAL board */
STM_EVAL_LEDInit(LED1);
STM_EVAL_LEDInit(LED2);
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_EXTI);
STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
/* USARTy and USARTz configuration -------------------------------------------*/
/* USARTy and USARTz configured as follow:
- BaudRate = 9600 baud
- Word Length = 9 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/* Configure USARTy */
USART_Init(USARTy, &USART_InitStructure);
/* Configure USARTz */
USART_Init(USARTz, &USART_InitStructure);
/* Enable the USARTy */
USART_Cmd(USARTy, ENABLE);
/* Enable the USARTz */
USART_Cmd(USARTz, ENABLE);
/* Set the USARTy Address */
USART_SetAddress(USARTy, 0x1);
/* Set the USARTz Address */
USART_SetAddress(USARTz, 0x2);
/* Select the USARTz WakeUp Method */
USART_WakeUpConfig(USARTz, USART_WakeUp_AddressMark); //被地址标记唤醒
while (1)
{
/* Send one byte from USARTy to USARTz */
USART_SendData(USARTy, 0x33);
/* Wait while USART1 TXE = 0 */
while(USART_GetFlagStatus(USARTz, USART_FLAG_TXE) == RESET)
{
}
if(USART_GetFlagStatus(USARTz, USART_FLAG_RXNE) != RESET)
{
if(USART_ReceiveData(USARTz) == 0x33)
{
STM_EVAL_LEDToggle(LED1);
Delay(0x5FFFF);
STM_EVAL_LEDToggle(LED2);
Delay(0x5FFFF);
STM_EVAL_LEDToggle(LED3);
Delay(0x5FFFF);
STM_EVAL_LEDToggle(LED4);
Delay(0x5FFFF);
}
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
0x101 这是一个16位数据了, 二进制是 0000 0001 0000 0001 最高位不是1啊
如果最高位是1不应该是0x81吗? 1000 0001
这相关的介绍,好像都没讲太明白
一周热门 更多>