Работают в связке МК XMEGA32D4 и AT45DB041D. Использую команду Continuous Array Read (Low Frequency Mode: 03H): Up to 33MHz, размер страницы 256 байт ( установлено и проверено чтением регистра статуса). При переходе между страницами считываются данные не со следующей страницы, а 0xff.
В чем может быть проблема? Не могу понять(
CODE
void continuous_low_freq_read(unsigned char* in_data, unsigned int page_address, unsigned int byte_address, unsigned int byte_count)
{
unsigned char dummy;
unsigned int i;
set_address_bytes(page_address,byte_address);
chip_select();
// opcode
dummy=SPI_TX_RX(comm_cont_read_low);
// three address bytes
for (i=0;i<3;i++) dummy=SPI_TX_RX(spi_addr_byte[i]);
// input data
for (i=0; i<byte_count; i++) in_data[i]=SPI_TX_RX(0xaa);
chip_deselect();
}
unsigned char SPI_TX_RX(unsigned char data)
{
SPIC.DATA=data;
while(!(SPIC.STATUS&SPI_IF_bm));
return SPIC.DATA;
}
void set_address_bytes(unsigned int page_address, unsigned int byte_address)
{
unsigned int temp;
temp=page_address;
temp>>=7;
spi_addr_byte[0]=(unsigned char) temp;
temp=(page_address&0x007F);
temp<<=1;
spi_addr_byte[1]=((unsigned char)(temp))|((unsigned char)(byte_address>>8));
spi_addr_byte[2]=(unsigned char)(byte_address);
}
#define chip_select() PORTD.OUT&= ~0x02
#define chip_deselect() PORTD.OUT|= 0x02
// command codes for at45
#define comm_cont_read_low 0x03
{
unsigned char dummy;
unsigned int i;
set_address_bytes(page_address,byte_address);
chip_select();
// opcode
dummy=SPI_TX_RX(comm_cont_read_low);
// three address bytes
for (i=0;i<3;i++) dummy=SPI_TX_RX(spi_addr_byte[i]);
// input data
for (i=0; i<byte_count; i++) in_data[i]=SPI_TX_RX(0xaa);
chip_deselect();
}
unsigned char SPI_TX_RX(unsigned char data)
{
SPIC.DATA=data;
while(!(SPIC.STATUS&SPI_IF_bm));
return SPIC.DATA;
}
void set_address_bytes(unsigned int page_address, unsigned int byte_address)
{
unsigned int temp;
temp=page_address;
temp>>=7;
spi_addr_byte[0]=(unsigned char) temp;
temp=(page_address&0x007F);
temp<<=1;
spi_addr_byte[1]=((unsigned char)(temp))|((unsigned char)(byte_address>>8));
spi_addr_byte[2]=(unsigned char)(byte_address);
}
#define chip_select() PORTD.OUT&= ~0x02
#define chip_deselect() PORTD.OUT|= 0x02
// command codes for at45
#define comm_cont_read_low 0x03
Запись страницы и чтение в рамках одной страницы происходят корректно.