完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,我有两个PIC18F70J90微控制器,我想来回交流。我想从一台PC机到一个微控制器进行通信。然后SPI从微控制器到第二微控制器。然后从第二微控制器UART到PC或另一台PC上的另一个COM端口。我也想向后通信(UART到第二微控制器),SPI从第二微控制器到第一微控制器,接着是UART到PC。到目前为止,我已经能够通过将第一微控制器编程为主机而将第二微控制器编程为奴隶来进行单向通信。我不知道如何向后沟通。换句话说,如何从主从数据写入SPI。我的代码相当简单。到目前为止,我一直在使用一个中断来对主和从接收UART字节并将它们缓冲成一个数组。我试图阻止自己创建一个通信协议,以从从属节点获得字节。当我接收UART字节到从微控制器时,我尝试发送一个标志数字输出信号,告诉主从在从属写入时开始读取。然而,现在的问题是主不会从奴隶那里接收任何字节。我已经附上了我的主人。C和奴隶。C文件作为文本文件。
SXAV.TXT(9.27 KB)-下载150次 以上来自于百度翻译 以下为原文 Hi, I have two PIC 18F87J90 microcontrollers which I would like to communicate back and forth from. I would like to communicate from a PC to a microcontroller. Then SPI from microcontroller to a second microcontroller. Then UART from second microcontroller to a PC or another PC on a different COM port. I would like to communicate backward as well (UART to second microcontroller), SPI from second microcontroller to first microcontroller followed by UART to PC. So far I have been able to communicate one way by programming the first microcontroller as a master and the second as a slave. I am not sure how to communicate backwards. In other words how to SPI write data from slave to master. My code is fairly straightforward. I have been using so far one interrupt for the master and slave to receive the UART bytes and buffer them into an array. I'm trying to prevent myself from creating a communication protocol to obtain bytes from the slave. When I receive UART bytes to the slave microcontroller, I then attempt to send a flag digital output signal to tell the master to begin reading while the slave writes. However, the issue now is the master does not receive any bytes from the slave. I have attached my master.c and slave.c files for your review as text files. Thanks --Brad Attachment(s) master.txt (9.15 KB) - downloaded 212 times slave.txt (9.27 KB) - downloaded 150 times |
|
相关推荐
2个回答
|
|
没有一个SPI奴隶可以从SPI大师那里“请求注意”:你必须一直做这一个民意调查,当奴隶有数据可用时报告这个情况。I2C你可以使用一些“诡计”来获得双向请求:但是,如果你真的需要这个,我也会使用USAT。为什么WER?你计划SPI吗?速度?
以上来自于百度翻译 以下为原文 There's no way a SPI slave can "request attention" from an SPI master: you have to make this one poll all the time and report the case when slave had data available. With I2C you may use some "trick" and get the bi-directional requests work: but if you really need that, I'd use USART as well. Why were you planning SPI? Speed? |
|
|
|
感谢快速反馈达里奥。是的,我知道有奴隶请求主写入数据是一项艰巨的任务,如果不是不可能的话。我将阅读I2C的PIC18F70J90双向通信。截至目前,我正在使用增强异步USAT从PC到微控制器1(主)和微控制器2到PC(从机)。有一个第二个USAT,我可以使用称为可寻址同步USAT。对不起,我还没有深入阅读可寻址同步USAT。你认为我可以使用增强异步异步USAT和可寻址同步USAT(增强型异步USAT从PC到每个微控制器和可寻址的同步USAT在两个微控制器之间)?要回答关于SPI速度的问题:我修改了主代码来发送一个字节序列(0xAA,0x55,0x0d)。字节序列是相反的SDI从主数据,这是奇怪的,我认为SPI。奴隶在这项测试中基本上什么也不做。捕获中的比特率示出了460 ns或2兆波特的比特宽度脉冲。我的SPI时钟运行在2兆赫。
以上来自于百度翻译 以下为原文 Thanks for the quick feedback Dario. Yes, I understand that having the slave request the master to write data is a difficult task, if not impossible. I will read up on I2C for the PIC18F87J90 for bidirecitonal communication. As of now I am using Enhanced Asynchronous USART for talking from the PC to microcontroller 1 (master) and microcontroller 2 to PC (slave). There is a second USART I can use called Addressable Synchronous USART. I'm sorry I haven't read up in depth on Addressable Synchronous USART. Do you think I can use both Enhanced Asynchronous USART and Addressable Synchronous USART (Enhanced Asynchronous USART from PC to each of the microcontrollers and Addressable Synchronous USART in between the two microcontrollers)? To answer your question about the speed of SPI: I modified the master code to send a byte sequence (0xAA, 0x55, and 0x0d). The byte sequence is reversed for SDI slave to master datawhich is odd I thought for SPI. The slave is basically doing nothing in this test. The bit rate in the capture shows a bit width pulse of 460 ns or ~2 Mbaud. I have the SPI clock run at 2 MHz. |
|
|
|
只有小组成员才能发言,加入小组>>
5237 浏览 9 评论
2026 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3201 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
772浏览 1评论
662浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
590浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
672浏览 0评论
572浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 09:36 , Processed in 1.226553 second(s), Total 78, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号