完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,我需要帮助。我正在尝试使用一个PIC24FJ256GA704在W25Q16 EEPROM上写和读。我需要为页面写3字节,确认这是写的,然后读它们。当EEPROM芯片满时,我必须保存第一扇区上的最后3个字节,并且擦除芯片的其他扇区。我用MCC用XC16编译器配置SPI和MPLAB X 3.65。我写的代码:SPI.HSPI.C:对我好一点……我是新手!谢谢你的帮助。
以上来自于百度翻译 以下为原文 Hi, I need help. I'm trying to write and read on a w25q16 eeprom using a PIC24FJ256GA704. I need to write 3 bytes for page, verify if this are written, and read them. When the eeprom chip is full, I have to save the last 3 bytes on the first sector, and the erase the other sectors of the chip. I used MCC to configure SPI and MPLAB X 3.65 with XC16 compiler. The code I wrote: SPI.h #ifndef SPI_H #define SPI_H #ifdef __cplusplus extern "C" { #endif #ifdef __cplusplus } #endif #endif /* SPI_H */ #include "utils.h" #include "SPI_eeprom.h" void spi_send_8bit(uint8_t cmd); void spi_send_address(uint32_t address); void spi_write_page(uint32_t address, uint8_t data); uint8_t spi_read(uint32_t address); SPI.c: #include "SPI.h" void spi_send_8bit(uint8_t cmd) { cmd = flipbits(cmd); uint8_t buff[8] = {0}; int i = 0; for (i = 0; i < 8; i++) { if ((cmd & 1) > 0) buff = 1; else buff = 0; } PCSO_LAT = set_low; SPI1_Exchange(buff, NULL); PCSO_LAT = set_high; } void spi_send_address(uint32_t address) { address = flip32bit(address); uint8_t buff[32] = {0}; int i = 0; for( i = 0; i < 24; i++) { if((address & 1) > 0) buff = 1; else buff = 0; PCSO_LAT = set_low; SPI1_Exchange(buff, NULL); PCSO_LAT = set_high; } } void spi_write_page(uint32_t address, uint8_t data) { spi_send_8bit(CMD_WREN); //write enable spi_send_address(address); spi_send_8bit(data); } uint8_t spi_read(uint32_t address) { spi_send_address(address); spi_send_8bit(CMD_READ); return SPI1_Exchange8bit(NULL); } Be kind with me...I'm a newbie! Thanks in advance for your help. |
|
相关推荐
5个回答
|
|
你的问题是什么?代码是否如预期的那样工作?如果是这样的话,那么你需要告诉我们它在做什么是错误的。苏珊
以上来自于百度翻译 以下为原文 What is your question? Does you code not work as expected? If that is the case then you need to tell us what it is doing that is wrong. Susan |
|
|
|
对不起,我忘了这个问题。代码(部分代码)不像预期的那样工作,所以我需要一些帮助,因为我不理解SPI通信是如何在这个PIC上使用这种闪存(WiNoLTW25Q16)的。谢谢您的回复!
以上来自于百度翻译 以下为原文 Sorry...I forgot the question. The code (partial code) is not working as expected, so I need some help because I didn't understood how SPI communication works on this PIC with this type of flash memory (winbond w25q16). Thanks for your reply! |
|
|
|
苏珊问了三个问题。你回答了“1”和“2”,“3”是用来解释你所期望的和你得到的。
以上来自于百度翻译 以下为原文 Susan asked three questions. You answered #1 and #2. #3 was to explain what you expected, and what you got. |
|
|
|
当我们等待您的答复时,这里有一些可能对您有帮助的信息。SPI是一个相当低的协议,它在主设备和从设备之间交换两个值:主设备向从属服务器发送一个值,同时从服务器向主机发送一个值。那就是全部!在硬件级别,您需要确保数据被放到总线上,并在主时钟和从机上读取相同的时钟转换。在微芯片世界中,这意味着在某些情况下获得CKP和CKE位以及SMP位。在上面,您需要在任何时间点定义值“均值”。通常是从属设备定义它需要什么信息以及它将发送什么信息。在这种情况下,你需要查看W25Q16 EEPROM数据表,以查看它期望什么值以及它将如何解释这些值。数据表显示,对于它所理解的每个命令,命令值(主将发送给从机;主机也将忽略此时从属服务器发送的任何内容)以及此后必须交换的任何值。例如,数据表的图8显示了“读”。结构。它显示了主控器发送指令,3个地址值(而忽略了从属服务器可能返回的任何内容),然后发送一个虚拟值(从属者将忽略此时间),而从属服务器从内存中返回该值。如果我是你,我会先确保SPI连接工作正常。你可以通过读取JEDEC ID或设备ID值来做这件事,因为你应该知道你将从奴隶那里得到什么。如果你不是这样的话,你需要解决这个问题,否则就没有其他的工作了,但是如果你能做到这一点,那么你就可以根据你的知识来执行你真正需要使用的操作。我不知道“fLIPTITE”函数是什么,以及为什么你要在“sEndoSpix8BIT”函数中解释“CMD”参数的位(我想你还是有一个bug),但是这对于一些非常简单的事情来说似乎是很有用的。苏珊
以上来自于百度翻译 以下为原文 While we wait for your reply, here is some information that might be helpful to you. SPI is a fairly low level protocol that exchanges two values between a master and a slave device: the master sends a value to the slave at the same time as the slave sends a value back to the master. That is all it is! At the hardware level you need to make sure that the data is being put onto the bus and being read on the same clock transitions by both the master and the slave. In the Microchip world, that means getting the CKP and CKE bits correct as well as the SMP bit in some cases. Above that you need to define what the values "mean" at any point in time. Quite often it is the slave device that defines what information it needs and what information it will send back. In your case, you need to look at the W25Q16 EEPROM data sheet to see what values it expects and how it will interpret those values. The data sheet shows, for each command that it understands, the command value (which the master will send to the slave; the master will also ignore whatever the slave sends back at this time), and any values that must be exchanged after that. For example, Figure 8 of the data sheet shows a "read" instruction. It shows the master sending the instruction, 3 address values (all the while ignoring whatever the slave may be sending back) and then sending a dummy value (which the slave will ignore this time) while the slave sends back the value from memory. All of that is the protocol that is define *above* the SPI protocol. If I were you, I would start off by making sure that the SPI connection is working. You could do that by reading the JEDEC ID, or Device ID values as you should know what you will be getting back from the slave. If you are not then you need to sort out the problem or nothing else will work, However if you can do that, then you can build on your knowledge to perform the operations you really need to use. Looking at your code, you seem to be making life a bit hard for yourself. I have no idea what the 'flipbits' function does and why you are trying to interpret the bits of the 'cmd' parameter in the 'send_spi_8bits' function (and I think you have a bug there anyway) but this seems to be a lot of work for something that is really very simple. Susan |
|
|
|
谢谢你的回复,我写的就像你写的,我不知道SPI是如何工作的。我使用了MCC的交换函数,它工作得很好。为了让生活更简单,我使用了逻辑分析仪,我知道问题在哪里。我没有发送哑字节并等待响应,所以在分析器上,我的代码生成的“波”是错误的。现在工作得很好。谢谢您的解释!这很有帮助!
以上来自于百度翻译 以下为原文 Thanks for your reply. I made like you wrote and I undestood how SPI works. I used the exchange functions that MCC genereted, and it works well. To make me the life easier, I used a logic analyzer, and I understood where was the problem. I didn't send dummy bytes and wait a response, so on the analyzer the "waves" generated by my code were wrong. Now works well. Thank you for your explanation! It was very helpful! |
|
|
|
只有小组成员才能发言,加入小组>>
5231 浏览 9 评论
2026 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3200 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
770浏览 1评论
658浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
587浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
668浏览 0评论
570浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-18 23:54 , Processed in 1.489660 second(s), Total 85, Slave 68 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号