参考官方例程做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);
}
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
en。谢谢。。现在能够分别发送不同数据给多个从机了。
就是从机收到数据之后还想要返回数据,没有调通。
请问在从机静默模式下,从机能发送吗?
没有看到文档中静默模式对发送的描述
---------------------------------
那我再试试,可能哪儿弄错了。。自己做着玩的,练习使用串口。
我之前把 接收到的 地址数据后面的那个数作为从机的发送条件,从机接收是正常,但是就是判断之后不执行发送,我还在里面加了个点亮led,也没有量。
以为是从机又进入静默了。。。
---------------------------------
你怎么调通这个多机通信的啊??我也是和你同样的问题,给我发一下你写的程序吧。。。谢谢
---------------------------------
以前的调试 笔记
读懂例程需要做的事情
通过flags进行两个串口之间半双工通信
(1、usart_y用TEXflag通过TxBuffer1发送data给USARTz
用存储在RxBuffer2中的RXNE flag与接收到的数据进行比较
"TransferStatus1" 由返回一个比较值
(2、USARTz发送TXE flag 通过 TxBuffer2 发送data 给USARTy
数据接收:用存储在RxBuffer1 中的RXNEflag与数据进行比较
比较结果存储在"TransferStatus2"
罗列出例程需要调用有用资源
发送一个数组
Usart 发送 接收 静默模式
调用相应资源
1)写程序rb发送8字节 c8接收并且显示在nokia上面
2)rb能够分别发送不同的数据到两个c8上面
3)c8接收到指定命令,发送数据给rb 在tft上面进行显示(调用tft、调试回传)
调试通过,一定要注意,定义变量的范围,u16,不然9位数据只能读取u8
STM32从机配置如下
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;
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_ITConfig(USART1,USART_IT_TC,ENABLE);
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
USART_WakeUpConfig(USART1,USART_WakeUp_AddressMark);//静默模式设置 1、USART_WakeUp_IdleLine 空闲总线唤醒//2、USART_WakeUp_AddressMark 地址标记唤醒
USART_SetAddress(USART1, 0x1); //设置地址 从机1
USART_ReceiverWakeUpCmd(USART1,ENABLE); //使能接收唤醒
。。。。。。同样配置
USART_SetAddress(USART1, 0x3); //设置地址 从机2
每次分别发送u16 send_data[8]={0x101,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
u16 send_data4[8]={0x103,0x04,0x05,0x06,0x07,0x08,0x09,0x10};
可以找到从机且接收准确,现在有这种现象:第一次从机接收到0x101(或0x103)唤醒后接收数据正常,然后过5s我直接发送u16 send_data3[8]={0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10};从机不能接收数据,但发送u16 send_data4[8]={0x103,0x04,0x05,0x06,0x07,0x08,0x09,0x10};从机可以正常接收数据
---------------------------------
十分感谢,已经调通了。。。
一周热门 更多>