在winbond W25Q32上写入大于256字节的数据时遇到问题。 我正在使用Quectel MC60(Eclipse IDE)进行编程。问题是我可以写一个页面。
顺序如下:
写write(page_addr,buff)// buff是要写入的数据字节
Ql_strcpy(buff3,“ EDIT(11-MAR-2014):_read_page低层函数存在问题,我忘记将CS HIGH拉高,然后在函数开始时将CS拉低这意味着如果_read_page是您调用的第一个函数,则CS可能还不是很高,因此如果没有有效的/ CS 1-> 0转换_read_page将无法正常运行,这是第一次调用。很好,因为它将/ CS保留为1。但是很小”);
//这是缓冲区
代码如下:
void proc_main_task(void)
{
s32 ret;
ST_MSG msg;
bool keepGoing = TRUE;
u8 ar[255];
u8 counter=0xf0,temp_counter=0;
char counter_s[6];
Ql_memset(ar,0,sizeof(ar));
// Register & open UART port
Ql_UART_Register(UART_PORT1, CallBack_UART_Hdlr, NULL);
Ql_UART_Open(UART_PORT1, 115200, FC_NONE);
Ql_UART_Register(UART_PORT2, CallBack_UART_Hdlr, NULL);
Ql_UART_Open(UART_PORT2, 115200, FC_NONE);
APP_DEBUG("\r\n<-- OpenCPU: SPI TEST! -->\r\n")
//chnnlNo, //pinClk, //pinMiso, //pinMosi, //pinCs, //spiType
ret = Ql_SPI_Init(USR_SPI_CHANNAL,PINNAME_PCM_IN,PINNAME_PCM_SYNC,PINNAME_PCM_OUT,PINNAME_PCM_CLK,spi_usr_type);
if(ret <0)
{
APP_DEBUG("\r\n<-- Failed!! Ql_SPI_Init fail , ret =%d-->\r\n",ret)
}
else
{
APP_DEBUG("\r\n<-- Ql_SPI_Init ret =%d -->\r\n",ret)
}
ret = Ql_SPI_Config(USR_SPI_CHANNAL,1,0,0,10000); //config sclk about 10MHz;
if(ret <0)
{
APP_DEBUG("\r\n<--Failed!! Ql_SPI_Config fail ret=%d -->\r\n",ret)
}
else
{
APP_DEBUG("\r\n<-- Ql_SPI_Config =%d -->\r\n",ret)
}
//init cs pin
if (!spi_usr_type)
{
Ql_GPIO_Init(PINNAME_PCM_CLK,PINDIRECTION_OUT,PINLEVEL_HIGH,PINPULLSEL_PULLUP); //CS high
}
u8 buff1[255]={0};
u16 addr=0,dev_id=0;
u8 i=0,counter1=0;
u8 buff3[1024];
u8 buff2[255]={0};
Ql_memset(buff3,0,sizeof(buff3));
Ql_strcpy(buff3,"EDIT (11-MAR-2014): There was an issue with the _read_page low-level function, I had forgotten to pull CS HIGH before pulling it LOW at the start of the function, like the other functions. This means if _read_page is the first function you call, CS may not already be high, so without a valid /CS 1->0 transition _read_page will not function properly, the first time it is called. The second time it would work fine because it leaves /CS as 1. Small but");
if (cmd_is_over1())
flash_rd_id(); // for reading JEDEC ID
else
APP_DEBUG("error.\r\n");
dev_id = Ql_atoi(s);
APP_DEBUG("DEVICE ID: %d\r\n",dev_id);
if(!Ql_strcmp(s,"4016"))
APP_DEBUG("Number of pages are 16384.\r\n")
else
APP_DEBUG("Number of pages error.\r\n")
ql_winbond_flash_block_unlock(); // unlock flash block
if (cmd_is_over1())
flash_rd_id2(); // For reading MID /DID
else
APP_DEBUG("error.\r\n")
APP_DEBUG("buff3 %s\r\n",buff3);
// for(counter=0;counter<50;counter++) // for reading
// {
Ql_memset(buff1,0,sizeof(buff1));
if (cmd_is_over1())
{
flash_rd_data1(counter,buff1,255);
cmd_is_over1();
}
else
APP_DEBUG("error.\r\n")
if (cmd_is_over1())
{
flash_rd_data1((counter+1),buff1,255);
cmd_is_over1();
}
else
APP_DEBUG("error.\r\n")
Ql_Sleep(50);
counter1=Ql_atoi(buff1);
APP_DEBUG("counter1 =%d\r\n",counter1);
// counter1=temp_counter; // check
Ql_memset(counter_s,0,sizeof(counter_s));
counter1++;
Ql_sprintf(counter_s,"%d",counter1);
APP_DEBUG("counter_s =%s\r\n",counter_s);
// }
// Ql_Sleep(500);
if (cmd_is_over1())
flash_erase_sector1(0);
else
APP_DEBUG("error.\r\n")
// for(counter=0;counter<50;counter++) // for writing
// {
if (cmd_is_over1())
{
// flash_wr_data(counter,my_itoa(counter,ar,10),sizeof(my_itoa(counter,ar,10)));
/// flash_wr_data(counter,"India is a beautiful country",Ql_strlen("India is a beautiful country"));
flash_wr_data(counter,buff3,Ql_strlen(buff3));
// flash_wr_data(counter,counter_s,Ql_strlen(counter_s));
cmd_is_over1();
}
// flash_wr_data(counter,"India\0",sizeof("India\0"));
else
APP_DEBUG("error.\r\n")
Ql_Sleep(50);
// }
// Ql_memset(buff1,0,sizeof(buff1));
// if (cmd_is_over1())
// flash_rd_data1(addr,buff1,255);
while (keepGoing)
{
Ql_OS_GetMessage(&msg);
switch(msg.message)
{
default:
break;
}
}
}