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

2个职位/ 0个新职位
最后发表
liuluan002
离线
最后看到:4个月3个星期前
加入:2015-11-27 14:24
如何在14583芯片组内动态地读取和写入数据到闪存中

嗨,对话框中,

我试图让程序写和读它自己的闪光一些传感器数据到它。它总是失败,因为第二次写入它,我验证写入的数据再次读取它。请问你对解决这个问题有什么建议吗?

我的代码如下:

无符号字符rd_data [256];
无符号字符wr_data [256];

const unsigned char *nData, unsigned short wLength

static const unsigned short 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、
0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 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, 0xb01, 0x2bc0, 0x2a80, 0xea41,
0x01, 0x2ec0, 0x2f80, 0x41, 0x2d00, 0xc1, 0x2c81, 0x2c40,
0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
0xa001, 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, 0x8710, 0x47c0, 0x4680, 0x8641,
0x8201、0x42c0、0x4380、0x8341、0x4100、0x81c1、0x8081、0x4040};

无符号字符nTemp;
unsigned short wCRCWord = 0xFFFF;

而(wLength——)

nTemp = *nData++ ^ wCRCWord;
wCRCWord > > = 8;
wCRCWord ^ = wCRCTable [nTemp];

返回wCRCWord;

静态孔隙da14583_spi_flash_init(空白)

SPI_Pad_t cs_pad_param;

//配置内部flash GPIOS
GPIO_ConfigurePin(DA14583_SPI_FLASH_EN_GPIO_PORT, DA14583_SPI_FLASH_EN_GPIO_PIN, OUTPUT, PID_SPI_EN, true);
GPIO_ConfigurePin(DA14583_SPI_FLASH_CLK_GPIO_PORT, DA14583_SPI_FLASH_CLK_GPIO_PIN, OUTPUT, PID_SPI_CLK, false);
GPIO_ConfigurePin(DA14583_SPI_FLASH_DO_GPIO_PORT, DA14583_SPI_FLASH_DO_GPIO_PIN, OUTPUT, PID_SPI_DO, false);
GPIO_ConfigurePin(DA14583_SPI_FLASH_DI_GPIO_PORT, DA14583_SPI_FLASH_DI_GPIO_PIN, INPUT, PID_SPI_DI, false);

cs_pad_param。端口= DA14583_SPI_FLASH_EN_GPIO_PORT;
cs_pad_param。销= DA14583_SPI_FLASH_EN_GPIO_PIN;

//初始化SPI驱动
spi_init(&cs_pad_param, SPI_MODE_8BIT, SPI_ROLE_MASTER, SPI_CLK_IDLE_POL_LOW, SPI_PHA_MODE_0, SPI_MINT_DISABLE, SPI_XTAL_DIV_8);
//初始化SPI Flash驱动
spi_flash_init (DA14583_SPI_FLASH_SIZE DA14583_SPI_FLASH_PAGE_SIZE);

//启动flash
spi_flash_release_from_power_down ();

静态孔隙da14583_spi_flash_release(空白)

//关闭flash
spi_flash_power_down ();
//释放SPI控制器
spi_release ();

//释放内部flash gpio
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) //写入flash并加载应用程序的白名单到内存中

/ / system_init ();
periph_init ();

unsigned short wcrc= 0xFFFF;
无符号字符crcH;
无符号字符crcL;

int16_t btrd;
无符号字符我;
/ / uint16_t read_size = 256;
Unsigned char write_size = 256;//将该变量设置为所需的读大小
memset (rd_data 0 x00,256);
memset (wr_data 0 x00,256);

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

/ / memcpy (wr_data + 3 white_addr2 6);

For (i = 0;我< 6;我+ +)

wr_data [3 + i) = white_addr2[我];

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

/ / white_addr

#如果DEBUG_LOG
printf_string(“\ n \ r \ n \ r whitelist_Setup = ");
printf_byte (whitelist_Setup);
uart2_init (UART_BAUDRATE_115K2 3);
# endif

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内部flash

#如果DEBUG_LOG
printf_string(“\ n \ r写闪:\ n”);
uart2_init (UART_BAUDRATE_115K2 3);
For (i = 0;我< write_size;我+ +)

printf_byte (wr_data[我]);
printf_string (" ");
uart2_init (UART_BAUDRATE_115K2 3);

printf_string(“\ n”);
# endif

spi_flash_page_program (wr_data,0 x1f800 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);

#如果DEBUG_LOG
printf_string(“\ n \ r \ n \ r双重检查…”);
uart2_init (UART_BAUDRATE_115K2 3);
# endif

btrd = spi_flash_read_data(rd_data, 0x1F800, write_size);
/ /显示结果
#如果DEBUG_LOG
printf_string("\n\r\n\rL218再次读取flash \n");
uart2_init (UART_BAUDRATE_115K2 3);
For (i = 0;我< write_size;我+ +)

printf_byte (rd_data[我]);
printf_string (" ");

printf_string("\n\r\n\r L493 Bytes Read: 0x");
printf_byte((btrd >> 8) & 0xFF);
printf_byte ((btrd) & 0 xff);
printf_string (" \ n \ r ");
uart2_init (UART_BAUDRATE_115K2 3);
# endif

wcrc = CRC16 (rd_data 10);
crcH = wcrc / 256;
crcL = wcrc % 256;

如果((crcH = = wr_data [10]) & & (crcL = = wr_data [11]))

#如果DEBUG_LOG
printf_string(“\ nCRC正确\ n \ r”);
uart2_init (UART_BAUDRATE_115K2 3);
# endif

#如果DEBUG_LOG
printf_string(“\ n \ r \ n \ r whitelist_Setup = ");
printf_byte (whitelist_Setup);
uart2_init (UART_BAUDRATE_115K2 3);
# endif

whitelist_Setup = 1;

/ / memcpy (ADDR_TARGET white_addr 6);


其他的

#如果DEBUG_LOG
printf_string(“\ nCRC错误\ n \ r”);
uart2_init (UART_BAUDRATE_115K2 3);
# endif

//释放DA14583内部flash
da14583_spi_flash_release ();

flagBCT2 = 0;
flagBCT1 = 0;
BCT1 = 0;
/ /返回状态;

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

设备:
MT_dialog
离线
最后看到:1个月1个星期前
工作人员
加入:2015-06-08 34
嗨liuluan002,

嗨liuluan002,

问题的描述是非常通用的,可以是很多东西的副作用,它可以是一个错误写读数据时也可能是一个错误,我可以建议看看peripheral_examples和spi项目,项目执行写入和读取的闪光,所以你可以把它作为一个例子。

由于MT_dialog