industrialNETworXnetx

Rainer Versteeg

Rainer Versteeg

| 14.10.2008 | 13:44 | 6 replies

read and write data to the SPI Flash

Hi,

I want to read and write data to the SPI Flash AT45DB041.

I want this only with the SPI Control Register, SPI Interrupt Register, SPI Status Register and SPI Data Register.

I know that, to read from the main Memory Page, the Opcode 52 H is needed with 24 address bit an 32 don´t care bits.

I don´t know how i must configure the SPI Register to send the above command and receive the requested data.

Can someone help me ?

Br,
Rainer

Rainer Versteeg

Rainer Versteeg

| 15.10.2008 | 10:41

Hi,

I use the following code to read out address 0 at memory page 0:

// Flash Zelle 0 auslesen
INIT_SPI();
CS_SELECT(0);
POKE(NETX_SPI_DATA, (0x52 | MSK_NETX_SPI_DATA_dr_valid0));
POKE(NETX_SPI_DATA, (0x00 | MSK_NETX_SPI_DATA_dr_valid0));
POKE(NETX_SPI_DATA, (0x00 | MSK_NETX_SPI_DATA_dr_valid0));
POKE(NETX_SPI_DATA, (0x00 | MSK_NETX_SPI_DATA_dr_valid0));

POKE(NETX_SPI_DATA, (0x00 | MSK_NETX_SPI_DATA_dr_valid0));
POKE(NETX_SPI_DATA, (0x00 | MSK_NETX_SPI_DATA_dr_valid0));
POKE(NETX_SPI_DATA, (0x00 | MSK_NETX_SPI_DATA_dr_valid0));
val=SPI_Master_Exchange_Byte(0x00);
val=SPI_Master_Read_Byte();
CS_DESELECT(0);

TLR_VOID INIT_SPI()
{
TLR_UINT32 uvalue;

uvalue=PEEK(NETX_SPI_CTRL);
POKE(NETX_SPI_CTRL,uvalue|0xE02000D6); //10 MHz Read/Write Enable
//SPI Interface enable
//Master Mode
//Falling edge of SPI_SCK is primary
}

TLR_VOID CS_SELECT(TLR_UINT8 device)
{
TLR_UINT32 uvalue;
uvalue=PEEK(NETX_SPI_CTRL);
switch (device)
{
case 0x00:
POKE(NETX_SPI_CTRL,uvalue|0x00000100);
break;
case 0x01:
POKE(NETX_SPI_CTRL,uvalue|0x00000200);
break;
case 0x02:
POKE(NETX_SPI_CTRL,uvalue|0x00000400);
break;
}
}

TLR_VOID CS_DESELECT(TLR_UINT8 device)
{
TLR_UINT32 uvalue;
uvalue=PEEK(NETX_SPI_CTRL);
switch (device)
{
case 0x00:
POKE(NETX_SPI_CTRL,uvalue&0xFFFFFEFF);
break;
case 0x01:
POKE(NETX_SPI_CTRL,uvalue&0xFFFFFDFF);
break;
case 0x02:
POKE(NETX_SPI_CTRL,uvalue&0xFFFFFBFF);
break;
}
}

unsigned char SPI_Master_Exchange_Byte(unsigned char bChar)
{
unsigned long ulFillLevel;

POKE(NETX_SPI_DATA, (bChar | MSK_NETX_SPI_DATA_dr_valid0));

/* wait for transfer cycle to be finished */
do
{
ulFillLevel = ((PEEK(NETX_SPI_STAT) & MSK_NETX_SPI_STAT_SR_out_fuel_val)
>> SRT_NETX_SPI_STAT_SR_out_fuel_val);
} while (ulFillLevel != 0);

return (PEEK(NETX_SPI_DATA) & 0xff);
}

unsigned char SPI_Master_Read_Byte()
{
unsigned long ulFillLevel;
unsigned char value;
/* wait for read cycle to be finished */
do
{
ulFillLevel = ((PEEK(NETX_SPI_STAT) & MSK_NETX_SPI_STAT_SR_in_fuel_val)
>> SRT_NETX_SPI_STAT_SR_in_fuel_val);
if (ulFillLevel>0)
value=PEEK(NETX_SPI_DATA);
} while (ulFillLevel != 0);
return (PEEK(NETX_SPI_DATA));
}

I dont get any data from the SPI Flash !.

What is wrong in this code snippset ?

Br,
Rainer

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 15.10.2008 | 12:15

Hi Rainer,

I found something interesting for you. Please check http://sourceforge.net/projects/muhkuh/. This project includes also the sources from the Bootwizards flashing stuff. I think this will help you out.

Regards
AJ

Rainer Versteeg

Rainer Versteeg

| 15.10.2008 | 17:24

Hi AJ,

Thank you for your help, but i dont find anything about SPI Register.

Can i see how the DRV_SFLReadFlash() function is programmed ? The function must use the SPI Register, or not ?

Br,
Rainer

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 16.10.2008 | 06:56

Hi Rainer,

yes. You will find the complete source of the Bootwizards SPI flash programming and reading stuff.

Rainer Versteeg

Rainer Versteeg

| 16.10.2008 | 08:40

Hi AJ,

Sorry but i dont find anything about SPI Register.
I have downloaded the file muhkuh_1.0.229.tar and muhkuh_1.0.228.0_setup.

Is this the file do you mean ?
Can you give me a tip where i can find the stuff ?

Br,
Rainer

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 16.10.2008 | 08:49

Login