完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好。我用PIC18F45 50(主控)控制另一个设备(从机),我需要从从属设备接收数据,并直接保存到SRAM存储器,通过USB将数据包发送到主机。从机每次发送27字节。我正在使用SPIXRead COMand并将信息保存到USB缓冲器中。所以,我假装使用一个while循环,并发送数据包时,大小达到270字节。我使用MikROC。1)有可能同时使用它们(SPI和USB)吗?2)如果是,我将在Read EngRoad变量中分配270个字节,并且可以在SRAM存储器中顺序地写入27个字节(27到27)吗?3)我不会收到来自PC USB的数据。有没有办法将数据包提升到540字节,并使用一个小的Read缓冲区变量?提前感谢!Rhuan。
以上来自于百度翻译 以下为原文 Hi everyone. I'm controlling another device (slave) with PIC18F4550 (master) and I need to receive data from slave and save directly to SRAM memory to send the packets to the host via USB. The slave sends 27 bytes per time. I'm using SPI_Read comand and saving the information into USB buffer. So, I pretend to use a while loop and send the packets when the size reachs 270 bytes. I'm using MikroC. 1) Is it possible to use them (SPI and USB) at the same time? 2) If yes, I will allocate 270 bytes in the write_buffer variable and can the 27 bytes be written sequentially (27-to-27) in SRAM memory? 3) I will receive no data from PC USB. Is there any way to raise the packet to 540 bytes and use a small read_buffer variable? Thanks in advance! Rhuan. |
|
相关推荐
3个回答
|
|
是的,但有资格-主要是在USB侧的东西。USB堆栈(至少是一个芯片从未使用MikroC)需要相当频繁地调用(大约每毫秒,如果我记得)。就硬件接口而言,它是中断驱动的,但需要经常注意和注意。(这适用于微芯片USB堆栈的两种模式),这完全取决于如何驱动SPI。如果它使用阻塞功能,并且交换的发生速度不够快,那么你可能无法及时恢复到USB堆栈的服务。另一方面,如果你通过中断使用SPI外围设备,那么你的主循环可以自由地处理USB堆栈,并且只在D中添加。来自SPI的ATA已经在缓冲区中,只猜测您的确切情况,但我以前见过类似的事情发生。苏珊
以上来自于百度翻译 以下为原文 Yes but with qualifications - mainly on the USB side of things. The USB stack (at least the Microchip one - never used MikroC) needs to be called fairly frequently (about every mSec if I recall). It is interrupt driven as far as the hardware interface is concerned but does need care and attention every so often. (This applies to both the modes for the Microchip USB stack). It all depends on how the SPI is being driven. If it uses blocking functions and the exchanges are not occurring fast enough then you might not be able to get back to service the USB stack in time. On the other hand if you use the SPI peripheral through interrupts then your main loop can be left free to handle the USB stack and only add in the data from the SPI when it is already in the buffer. Only guessing for your exact situation but I've seen similar things happen before. Susan |
|
|
|
谢谢你的支持,苏珊!我理解了你的观点,我同意,但我不会使用USB的实时SPI。我会给一些指令,只有在电源上的奴隶。所以,我会等待新的数据被读取,然后我将继续阅读。我的代码有大约300行。因此,我将更好地解释如下:函数(SPIX写);函数(SPIXRADE);SPIX写(和,HEX配置的奴隶和GT;)/ /如果PIN RB2=1,则至少有20条指令发送到SlaveVoice主();/ /表示来自奴隶的新数据已准备好被读取,并且它有27字节二进制INF。OsPiRead=UBSWRITEOSH缓冲器[270 ] //我想发送270字节的数据包给主机,我将SPI接收的数据直接保存到USB RAM中?我该怎么做呢?这就像SPI到USB转换器的内部转换。在这种情况下,可以将通过SPI接收的字节保存到变量中,然后将它们写入HIDIGrad中。最好的问候,Rhuan。
以上来自于百度翻译 以下为原文 Thanks for your support, Susan! I undestood your point and I agree with it, but I won't use real time SPI with USB. I will give some instructions to slave only in the power up. So, I'll wait for new data to be read, then I'll read continuously. My code has around 300 lines. So, I will explain as better I can below. function(SPI_Write); function(SPI_Read); SPI_Write( void main () if pin RB2 = 1; // indicates that new data from slave is ready to be read and it has 27 bytes of binary info SPI_Read = USB_write_buffer[270] // I would like to send 270 bytes packet to the host Can I save SPI received data directly into USB RAM? How can I do this? It's like a internal conversion of SPI-to-USB converter. In this case, it is possible to save the bytes received via SPI into variables, and then write them in the HID_Write? Best regards, Rhuan. |
|
|
|
您使用两个函数来读取和写入SPI接口使我感觉到,您可能不理解SPI是一个值交换协议——主机启动每个交换机,但它会在向它发送一个值的同时从接收端接收一个值。因此,您只需要一个函数——如果不关心返回的内容,则忽略返回的值;如果不关心发送的是什么,则发送一个哑值。当从加法器抬起PIN以表示它有值时,主机必须启动27个交换机。(在这个过程中,如果你的SPI函数是阻塞的,你可能会有定时问题。)你把从奴隶那里接收到的值放在你身上,就像你传递给USB外围设备和它们来自哪里的价值一样。如果你使用同一个程序缓冲区,那可能会有帮助。但是,我不知道你正在使用的USB堆栈,它是否使用内部缓冲区,如何访问它,以及如何在不传递缓冲指针的情况下启动USB传输(假设你已经)。个人的话,我会让我的主环路根据需要为USB外围设备服务。当我被告知SPI从属者有数据时,我会启动一个中断驱动的交换,将每个值存储在一个ISR中的一个缓冲区中(触发下一个交换,直到所有27个值都被交换),然后为主循环设置一个标志来执行USB写。苏珊。
以上来自于百度翻译 以下为原文 Your use of two functions to read from and write to the SPI interface makes me thing that perhaps you don't understand that the SPI is a value exchange protocol - the master initiates each exchange but it will receive a value from the slave at the same time as it sends a value to it. Therefore you only need one functions - if you don't care what is received back then ignore the returned value; if you don't care what is sent then send a dummy value. The master has to initiate each exchange. When the slave raises the pin to say it has values, the master must then initiate 27 exchanges. (It is during this process that you may have timing issues if your SPI function is blocking.) Where you put the values you received from the slave is up to you, as is what values you pass on to the USB peripheral and where they come from. If you use the same program buffer then that might help. However I have no idea of the USB stack that you are using and whether or not it uses an internal buffer, how you could access it and how you can initiate a USB transfer without passing a buffer pointer (on the assumption that you have already filled in some internal buffer). Personally, I would have my main loop servicing the USB peripheral as required. When I am told that the SPI slave has data, I would start an interrupt driven exchange that stores each value into a buffer in an ISR (triggering the next exchange until all 27 values have been exchanged) which then sets a flag for the main loop to perform the USB write. Susan |
|
|
|
只有小组成员才能发言,加入小组>>
5283 浏览 9 评论
2055 浏览 8 评论
1968 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3231 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2276 浏览 5 评论
820浏览 1评论
709浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
652浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
710浏览 0评论
605浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-12 03:13 , Processed in 1.308603 second(s), Total 81, Slave 65 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号