如何在14583芯片组内动态地读取和写入闪存中的数据

2个帖子/ 0新
最后一篇
Liuluan002.
离线
最后一次露面:4个月3周前
加入:2015-11-27 14:24
如何在14583芯片组内动态地读取和写入闪存中的数据

嗨对话框,

我正在尝试使程序写入并读取自己的闪存一些传感器数据。它始终失败,自第二次写入它,我通过再次读出书面数据来验证书面数据。你有一些建议解决问题吗?

我的代码如下:

unsigned char rd_data [256];
unsigned char wr_data [256];

无符号短期CRC16(Const Unsigned Char * NDATA,无符号短WLONGTH)
{

静态const unsigned短wcRctable [] = {
0x0000,0xc0c1,0xc181,0x0140,0xc301,0x03c0,0x0280,0xC241,
0XC601, 0X06C0, 0X0780, 0XC741, 0X0500, 0XC5C1, 0XC481, 0X0440,
0xcc01,0x0cc0,0x0d80,0xcd41,0x0f00,0xcfc1,0xce81,0x0e40,
0x0a00,0xcac1,0xcb81,0x0b40,0xc901,0x09c0,0x0880,0xc841,
0xD801,0x18C0,0x1980,0xD941,0x1b00,0xdbc1,0xda81,0x1a40,
0x1e00,0xdec1,0xdf81,0x1f40,0xdd01,0x1dc0,0x1c80,0xdc41,
0 x1400, 0 xd4c1 0 xd581 0 x1540, 0 xd701 0 x17c0 0 x1680, 0XD641,
0XD201, 0X12C0, 0X1380, 0XD341, 0X1100, 0XD1C1, 0XD081, 0X1040,
0xF001,0x30C0,0x3180,0xF141,0x3300,0xF3C1,0xF281,0x3240,
0x3600,0xF6C1,0xF781,0x3740,0xF501,0x35C0,0x3480,0xF441,
0x3c00,0xfcc1,0xfd81,0x3d40,0xff01,0x3fc0,0x3e80,0xfe41,
0xFA01,0x3AC0,0x3b80,0xfb41,0x3900,0xf9c1,0xf881,0x3840,
0X2800, 0XE8C1, 0XE981, 0X2940, 0XEB01, 0X2BC0, 0X2A80, 0XEA41,
0XEE01, 0X2EC0, 0X2F80, 0XEF41, 0X2D00, 0XEDC1, 0XEC81, 0X2C40,
0xe401,0x24c0,0x2580,0xe541,0x2700,0xe7c1,0xe681,0x2640,
0x2200,0xe2c1,0xe381,0x2340,0xe101,0x21c0,0x2080,0xe041,
0x001,0x60c0,0x6180,0xa141,0x6300,0xa3c1,0xa281,0x6240,
0X6600, 0XA6C1, 0XA781, 0X6740, 0XA501, 0X65C0, 0X6480, 0XA441,
0x6c00,0xacc1,0xad81,0x6d40,0xAF01,0x6fc0,0x6e80,0xae41,
0XAA01, 0X6AC0, 0X6B80, 0XAB41, 0X6900, 0XA9C1, 0XA881, 0X6840,
0x7800,0xb8c1,0xb981,0x7940,0xbb01,0x7bc0,0x7a80,0xba41,
0xbe01,0x7ec0,0x7f80,0xbf41,0x7d00,0xbdc1,0xbc81,0x7c40,
0xb401,0x74c0,0x7580,0xb541,0x7700,0xb7c1,0xb681,0x7640,
0X7200, 0XB2C1, 0XB381, 0X7340, 0XB101, 0X71C0, 0X7080, 0XB041,
0x5000,0x90c1,0x9181,0x5140,0x9301,0x53c0,0x5280,0x9241,
0X9601, 0X56C0, 0X5780, 0X9741, 0X5500, 0X95C1, 0X9481, 0X5440,
0x9c01,0x5cc0,0x5d80,0x9d41,0x5f00,0x9fc1,0x9e81,0x5e40,
0X5A00, 0X9AC1, 0X9B81, 0X5B40, 0X9901, 0X59C0, 0X5880, 0X9841,
0x8801,0x48c0,0x4980,0x8941,0x4b00,0x8bc1,0x8a81,0x4a40,
0x4e00,0x8ec1,0x8f81,0x4f40,0x8d01,0x4dc0,0x4c80,0x8c41,
0x4400,0x84c1,0x8581,0x4540,0x8701,0x47c0,0x4680,0x8641,
0X8201, 0X42C0, 0X4380, 0X8341, 0X4100, 0X81C1, 0X8081, 0X4040 };

未签名的char ntemp;
unsigned short wCRCWord = 0xFFFF;

而(Wlength--)
{
nTemp = *nData++ ^ wCRCWord;
wcrcword >> = 8;
wcrcword ^ = wccctable [ntemp];
}
return wCRCWord;
}

静态void da14583_spi_flash_init(void)
{
SPI_Pad_t cs_pad_param;

// configure internal flash GPIOS
gpio_configurepin(da14583_spi_flash_en_gpio_port,da14583_spi_flash_en_gpio_pin,输出,pid_spi_en,true);
gpio_configurepin(da14583_spi_flash_clk_gpio_port,da14583_spi_flash_clk_gpio_pin,输出,pid_spi_clk,false);
gpio_configurepin(da14583_spi_flash_do_gpio_port,da14583_spi_flash_do_gpio_pin,输出,pid_spi_do,false);
gpio_configurepin(da14583_spi_flash_di_gpio_port,da14583_spi_flash_di_gpio_pin,输入,pid_spi_di,false);

cs_pad_param.port = da14583_spi_flash_en_gpio_port;
cs_pad_param.pin = DA14583_SPI_FLASH_EN_GPIO_PIN;

//初始化SPI驱动程序
spi_init(&cs_pad_param,spi_mode_8bit,spi_rool_master,spi_clk_idle_pol_low,spi_pha_mode_0,spi_mint_disable,spi_xtal_div_8);
//初始化SPI闪存驱动程序
spi_flash_init(DA14583_SPI_FLASH_SIZE, DA14583_SPI_FLASH_PAGE_SIZE);

// Power up flash
SPI_FLASH_RELEASE_FROM_POWER_DOWN();
}

static void da14583_spi_flash_release(void)
{
//电源闪烁
spi_flash_power_down();
// Release SPI controller
spi_release();

// Release internal flash GPIOs
GPIO_ConfigurePin( DA14583_SPI_FLASH_EN_GPIO_PORT, DA14583_SPI_FLASH_EN_GPIO_PIN, OUTPUT, PID_GPIO, true );
gpio_configurepin(da14583_spi_flash_clk_gpio_port,da14583_spi_flash_clk_gpio_pin,input_pulldown,pid_gpio,false);
gpio_configurepin(da14583_spi_flash_do_gpio_port,da14583_spi_flash_do_gpio_pin,input_pulldown,pid_gpio,false);
gpio_configurepin(da14583_spi_flash_di_gpio_port,da14583_spi_flash_di_gpio_pin,input_pulldown,pid_gpio,false);
}

void updateWhiteListold(void) //write into flash and load the WhiteList into memory for application
{
//system_init();
periph_init();

无符号短wcrc = 0xffff;
unsigned char crcH;
无符号char crcl;

INT16_T BTRD;
unsigned char i;
//uint16_t read_size= 256;
unsigned char write_size = 256;//将此变量设置为所需的读取大小
Memset(RD_DATA,0x00,256);
memset (wr_data,0x00,256);

wr_data [0] = 0x01;
wr_data [1] = 0x12;
wr_data[2]=0x34;

// memcpy(wr_data + 3,white_addr2,6);

for(i = 0; i <6; i ++)
{

wr_data [3 + i] = white_addr2 [i];
}

WCRC = CRC16(WR_DATA,10);
WR_DATA [10] = WCRC / 256;
wr_data[11]=wcrc%256;

//white_addr

#if debug_log.
printf_string("\n\r\n\r whitelist_Setup=");
printf_byte(whitelist_setup);
UART2_INIT(UART_BAUDRATE_115K2,3);
#万一

da14583_spi_flash_init();

//上电外围设备的电源域
setBits16(PMU_CTRL_REG,PERIPH_SLEEP,0);
while (!(GetWord16(SYS_STAT_REG) & PER_IS_UP));

//启用焊盘
SetBits16(Sys_ctrl_reg,pad_latch_en,1);

//初始化DA14583内部闪存

#if debug_log.
printf_string(“\ n \ r写flash:\ n”);
UART2_INIT(UART_BAUDRATE_115K2,3);
for(i = 0; i {
printf_byte(wr_data[i]);
printf_string(“”);
UART2_INIT(UART_BAUDRATE_115K2,3);
}
printf_string(“\ n”);
#万一

spi_flash_page_program(wr_data, 0x1F800, write_size);

da14583_spi_flash_release();

da14583_spi_flash_init();

setBits16(PMU_CTRL_REG,PERIPH_SLEEP,0);
while (!(GetWord16(SYS_STAT_REG) & PER_IS_UP));

//启用焊盘
SetBits16(Sys_ctrl_reg,pad_latch_en,1);

#if debug_log.
printf_string(“\ n \ r \ n \ r double check ......”);
UART2_INIT(UART_BAUDRATE_115K2,3);
#万一

btrd = spi_flash_read_data(rd_data,0x1f800,write_size);
//显示结果
#if debug_log.
printf_string(“\ n \ r \ n \ rl218再次读取闪光灯\ n”);
UART2_INIT(UART_BAUDRATE_115K2,3);
for(i = 0; i {
printf_byte(rd_data [i]);
printf_string(“”);
}

printf_string(“\ n \ r \ n \ r l 493字节数:0x”);
printf_byte((btrd >> 8) & 0xFF);
printf_byte((btrd)&0xff);
printf_string(“\ n \ r”);
UART2_INIT(UART_BAUDRATE_115K2,3);
#万一

WCRC = CRC16(RD_DATA,10);
crcH=wcrc/256;
crcL=wcrc%256;

if((crch == wr_data [10])&&(crcl == wr_data [11]))
{
#if debug_log.
printf_string(“\ ncrc正确\ n \ r”);
UART2_INIT(UART_BAUDRATE_115K2,3);
#万一

#if debug_log.
printf_string("\n\r\n\r whitelist_Setup=");
printf_byte(whitelist_setup);
UART2_INIT(UART_BAUDRATE_115K2,3);
#万一

whitelist_setup = 1;

// memcpy(addr_target,white_addr,6);

}
别的
{
#if debug_log.
printf_string("\nCRC wrong\n\r");
UART2_INIT(UART_BAUDRATE_115K2,3);
#万一
}
// Release DA14583 internal flash
da14583_spi_flash_release();

flagbct2 = 0;
flagBCT1=0;
BCT1 = 0;
//return status;

//system_init();
// periph_init();
}

Device:
mt_dialog.
离线
最后一次露面:1个月1周前
职员
加入:2015-06-08 11:34
Hi liuluan002,

Hi liuluan002,

The description is very generic and the issue can be a side effect of many things, it can be an error to write or it might be an error when reading the data as well, what i can suggest is to have a look at the peripheral_examples and the spi project, the project performs writes and reads to the flash, so you can take that as an example.

谢谢mt_dialog.