初级会员
- 积分
- 80
- 金钱
- 80
- 注册时间
- 2020-8-10
- 在线时间
- 20 小时
|
楼主 |
发表于 2024-11-13 12:01:11
|
显示全部楼层
- //写入起始地址为:块地址BlockAddr(0~1023),页地址PageAddr(0~63),具体字节地址BytesAddr(0~2047)的连续Size个数据,数据个数(0~65535)
- w25n_status_t W25Nx_Buf_Write_Nx_Data(uint8_t *pData, uint16_t BlockAddr, uint8_t PageAddr, uint16_t BytesAddr, uint16_t Size)
- {
- uint8_t cmd[7];
- uint16_t i;
- uint8_t Page_data[2060];
- /* Configure the command */
- cmd[0] = WRITE_DATA_CMD; //0x02 //数据装入缓冲区命令
- cmd[1] = (uint8_t)((BytesAddr >> 8) & 0x07);
- cmd[2] = (uint8_t)(BytesAddr & 0xFF);
-
- cmd[3] = WRITE_INPUT_PAGE_ADDR_CMD; //0x10 //程序执行,写入主存区命令
- cmd[4] = Dummy_Byte;
- cmd[5] = (uint8_t)((BlockAddr >> 2) & 0xFF); //主存区页地址
- cmd[6] = (uint8_t)(((BlockAddr << 6)+PageAddr) & 0xFF);
-
-
- //先赋三个命令在开头
- for(i=0;i<3;i++)
- {
- Page_data[i] = cmd[i];
- }
- for(i=3;i<(Size + 3);i++) //存储页数据
- {
- Page_data[i] = *pData;
- pData++;
- }
-
-
- W25Q32_CS_CLR();
- if(ald_spi_send_byte_fast(&h_spi, WRITE_ENABLE_CMD) != OK)
- {
- W25Q32_CS_SET();
- return W25N_ERROR;
- }
- W25Q32_CS_SET();
-
- md_delay_us(100);
- W25Q32_CS_CLR();
- for(i=0;i<(Size + 3);i++)
- {
- if (ald_spi_send_byte_fast(&h_spi, Page_data[i]) != OK)
- {
- W25Q32_CS_SET();
- return W25N_ERROR;
- }
- }
- W25Q32_CS_SET();
- md_delay_us(100);
- //md_delay_1ms(10);
- W25Q32_CS_CLR();
- for(i=3;i<7;i++)//写剩余指令
- {
- if (ald_spi_send_byte_fast(&h_spi, cmd[i]) != OK)
- {
- W25Q32_CS_SET();
- }
- }
- W25_Wait_Busy();
- W25Q32_CS_SET();
- return W25N_OK;
-
-
- }
- /***********************************************************************************************
- ** name: W25_PageDataRead
- ** function: 读取指定页地址的数据,并移动到缓冲区
- **parameter: BlockAddr 写入的块地址(0-1023)
- PageAddr 写入的页地址(0-63)
- ** return: void
- ************************************************************************************************/
- void W25_PageDataRead(uint16_t BlockAddr,uint8_t PageAddr)
- {
- uint16_t i = 0;
- uint8_t cmd[4];
-
- cmd[0] = PAGE_READ_CMD; //主存区页数据传至缓冲区
- cmd[1] = Dummy_Byte;
- cmd[2] = (uint8_t)((BlockAddr >> 2) & 0xFF); //页地址
- cmd[3] = (uint8_t)(((BlockAddr << 6)|PageAddr) & 0xFF);
- W25Q32_CS_CLR();
- if (ald_spi_send_byte_fast(&h_spi, PAGE_READ_CMD) != OK) {
- W25Q32_CS_SET();
- }
- for (i = 0; i < 4; i++)
- {
- if (ald_spi_send_byte_fast(&h_spi, cmd[i]) != OK) {
- W25Q32_CS_SET();
- }
- }
- W25Q32_CS_SET();
- W25_Wait_Busy();
- }
- /***********************************************************************************************
- ** name: W25_Read
- ** function: 读取SPI FLASH,在指定地址开始读取指定长度的数据
- **parameter: pBuffer 数据存储区
- BytesAddr 写入的具体字节地址(0-1023)
- BlockAddr 写入的块地址(0-1023)
- PageAddr 写入的页地址(0-63)
- NumByteToWrite 要写入的数据个数(0-65535),该数不应该超过该页的剩余字节数!!!
- ** return: void
- 需要改造,和W25N.C文件里可以写多页的函数整合
- ************************************************************************************************/
- void W25_Read(uint8_t* pBuffer,uint16_t BlockAddr,uint8_t PageAddr,uint16_t BytesAddr,uint16_t NumByteToRead)
- {
-
- uint16_t i = 0;
- uint8_t cmd[4];
-
- int r_flag = 0;
- cmd[0] = READ_CMD; //读出缓冲区数据
- cmd[1] = (uint8_t)((BytesAddr >> 8) & 0x07);
- cmd[2] = (uint8_t)(BytesAddr & 0xFF);
- cmd[3] = Dummy_Byte;
-
- W25_PageDataRead(BlockAddr,PageAddr); //先读取页地址数据,送到缓冲区
- md_delay_1ms(10);
-
- W25Q32_CS_CLR(); //使能器件
- for (i = 0; i < 4; i++)
- {
- if (ald_spi_send_byte_fast(&h_spi, cmd[i]) != OK) {
- W25Q32_CS_SET();
- }
- }
- for(i = 0; i < NumByteToRead; i++){
- pBuffer[i] = ald_spi_recv_byte_fast(&h_spi, &r_flag); //循环读数
-
- if (r_flag != OK) {
- W25Q32_CS_SET();
-
- }
- }
-
- W25Q32_CS_SET();
- }
- void vol_made(void)//关闭-转换的数据存储-开启转换 外部音频输入
- {
- // uint8_t j,i;//,music_buf1[15000]
- // uint16_t k;
- if(voctype==3&&PPT_in[0]==0)//此时录得是前导音
- {
- while(PPT_in[0]==0 )//暂时用这个当判断条件 麦克风输入音频record_readay==2
- {
- md_delay_us(10);
- music_buf[mus]=(_env.buf[5]&0x0f00)>>8;// 比如 0x0c7a music_buf[0]=0x0c music_buf[1]=0x7a 后面再拼接起来
- music_buf[mus+1]=_env.buf[5]&0x00ff;
- if(mus>2000)
- {
- W25Nx_Buf_Write_Nx_Data( music_buf, 0, mus3, 0, 2000);
- mus3++;
- mus=0;
- }
- mus=mus+2;
- if(mus3>2)
- {
- mus3=0;
- record_readay=5;
- break;
- }
- }
-
- if(record_readay==5)
- {
- record_readay=3;
- keepvideo_led(1,OFF);
- keepvideo_led(3,OFF);
- }
- if(voc_in[2]==0)
- {
- mus=0;
- record_readay=3;
- }
- }
- // if(voctype==1||voctype==2)
- // {
- // if(PPT_in[0]==1&&ch_env[6].vol>0)//此时是外部输入音频 只要开始录音,就把此时的转换后的数值当做第1位开始存储
- // {
- // music_buf[mus]=ch_env[6].vol|0x0fff;//45us左右存一个值,0x0fff
- // mus++;
- // if(voc_in[2]==0)//只要按下停止键,数组就不再继续存[img]https://pica.zhimg.com/v2-cb0d564789c96e1c16887ca65b696f06_r.jpg[/img]?source=1def8aca
- // {
- // record_readay=3;
- // mus=0;
- // }
- // }
- // }
-
- }
复制代码 |
|