ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Суббота
23 ноября
156907
kostikp (18.05.2009 19:25, просмотров: 3576) reZident
AT45DB642D-SU и AVR: Вот пытаюсь писать данные во flash. вот процедуры: void AT45_write_buffer_begin(unsigned int addr) { AT45_CS_ON; AT45Ready(); SPI_Write_Byte(BUFFER_1_WRITE); // ok SPI_Write_Byte(0x00); SPI_Write_Byte((char)(addr>>13)); SPI_Write_Byte((char)addr); } void AT45_buf_to_mem(unsigned int addr) { AT45_CS_ON; AT45Ready(); SPI_Write_Byte(BUFFER_1_TO_PAGE_WITH_ERASE); // ok SPI_Write_Byte((char)(addr>>8)); SPI_Write_Byte((char)(addr<<3)); SPI_Write_Byte(0x00); AT45Ready(); AT45_CS_OFF; } void WRITE_BUFFER1_TO_MEM(unsigned char *m, unsigned int page) { unsigned int i; AT45_write_buffer_begin(0); for (i=0;i<PAGE_BYTES;i++) { SPI_Write_Byte(m[i]); } AT45_CS_OFF; AT45_buf_to_mem(page); } void AT45_read_buffer_begin(unsigned int addr) { AT45_CS_ON; AT45Ready(); SPI_Write_Byte(BUFFER_1_READ); // ok SPI_Write_Byte(0); SPI_Write_Byte((char)(addr>>13)); SPI_Write_Byte((char)addr); } void AT45_mem_to_buf(unsigned int addr) { AT45_CS_ON; AT45Ready(); SPI_Write_Byte(MAINPAGE_TO_BUFFER_1); // ok SPI_Write_Byte((char)(addr>>8)); SPI_Write_Byte((char)(addr<<3)); SPI_Write_Byte(0x00); AT45Ready(); AT45_CS_OFF; } void READ_BUFFER1_FROM_MEM(unsigned char *m,unsigned int index,unsigned char count, unsigned int page) { unsigned int i; AT45_mem_to_buf(page); AT45_read_buffer_begin(0); for (i=index;i<PAGE_BYTES;i++) { if(i<(index+count)) { m[i-index]=SPI_Read_Byte(); } else SPI_Read_Byte(); } AT45_CS_OFF; } #define PAGE_COUNT 8192 #define BLOCK_COUNT 1024 #define PAGE_BYTES 1056 #define BUFFER_1 0x00 #define BUFFER_2 0x01 #define BUFFER_1_WRITE 0x84 #define BUFFER_2_WRITE 0x87 #define BUFFER_1_READ 0xD1 #define BUFFER_2_READ 0xD3 #define BUFFER_1_TO_PAGE_WITH_ERASE 0x83 #define BUFFER_2_TO_PAGE_WITH_ERASE 0x86 #define MAINPAGE_TO_BUFFER_1 0x53 #define MAINPAGE_TO_BUFFER_2 0x55 #define PAGE_ERASE 0x81 #define BLOCK_ERASE 0x50 #define SECTOR_ERASE 0x7C вот текст программы: spi_init(); while(1) { TxData1(at45ReadVID()); TxData1(at45ReadStReG()); Del(1000); if(g==0) { g=1; AT45Mass[1]=0x0a; AT45Mass[200]=0x0b; WRITE_BUFFER1_TO_MEM(AT45Mass,10); Del(1000); AT45Mass[1]=0; AT45Mass[200]=0; READ_BUFFER1_FROM_MEM(AT45Mass,0,220,10); TxData1(AT45Mass[1]); TxData1(AT45Mass[200]); } } выводятся нули. регистр статуса и id считываются. я такж епробовал записать в буфур 0 и потом считать оттуда - работало. а вот через память не получаеся. подскажите что не так ?