is an appnote from Atmel how to use Dataflash with their AVR controllers.
You should be able to get what you need out of this.
Best regards
dvsoft
Joined: 28 Nov 2003 Posts: 46
Posted: Sat Dec 20, 2003 2:11 am
Hello
I use the following code with a AT45DB321B I hope that it will help you
Alain
//----------------------------------------------------------------------------
// SPI I/O
//
#ifndef __SPI_IO__
#USE fast_io(c)
#define SPI_SO PIN_A5 // SPI Out pin
#define SPI_SI PIN_A4 // SPI In pin
#define SPI_SCK PIN_E0 // SPI Out Clock pin
#define SPI_TRIS_A 0x30 // Tris on port A
#define SPI_TRIS_E 0x00 // Tris on port E
#endif
//----------------------------------------------------------------------------
// Function :write_SPI
// Version :0.1
// Author :Alain
//
// Usage :write_SPI(Data)
//
// Arguments:BYTE Data Data to write
//
// Return :void
//
// Modify :void
//
// Shift one Byte out on the falling edge of the clock.
//----------------------------------------------------------------------------
void write_SPI(BYTE Shift)
{
BYTE BitCnt = 8;
//--- Shifts out
do {
//--- Clock low
output_low(SPI_SCK);
//--- Bit = 1
if(Shift & 0x80)
output_high(SPI_SO);
//--- Bit = 0
else
output_low(SPI_SO);
Shift <<= 1;
//--- Clock high
output_high(SPI_SCK);
} while (--BitCnt);
}
//----------------------------------------------------------------------------
// Function :read_SPI
// Version :0.1
// Author :Alain
//
// Usage :Data = read_SPI(void)
//
// Arguments:void
//
// Return :BYTE Data -> Read result
//
// Modify :void
//
// Read one Byte in data on the rising edge of the clock.
//----------------------------------------------------------------------------
BYTE read_SPI()
{
BYTE Shift,BitCnt = 8;
//--- Shift in
do {
//--- Clock Low, high
output_low(SPI_SCK);
output_high(SPI_SCK);
Shift <<= 1;
//--- Bit = 0
if(!input(SPI_SI))
Shift &= ~1;
//--- Bit = 1
else
Shift |= 1;
} while (--BitCnt);
return (Shift);
}
//----------------------------------------------------------------------------
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum