R/W from AT45DB041D using ATmega16u4 through USB

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I'm trying to write and read data to the AT45DB041D dataflash. I'm using

MCU = ATmega16u4
WinAVR-20100110
LUFA-120219
Windows 7
AVR Studio

I can send the data from sensor (like thermistor etc.) to the windows terminal via MCU through USB.

Sensor -> MCU -> USB -> Terminal

I'm so graful to LUFA Library (Dean) and Chuck99's tutorial for that.

I've attached my dataflash (DF) ckt.

Now my aim is to write data to the mentioned dataflash.

Sensor -> MCU -> DF

and then read the data from DF

DF -> MCU -> USB -> PC

Last few days I was engaged with DF data sheet and avrfreaks (https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=34745&start=all&postdays=0&postorder=asc&sid=07d363492f079dd6aa286ae9b32e2eb4) web pages. As a newbie I'm trying to do some demo tests like DF_CheckCorrectOnboardChip. I tried to use ButtLoad code, though it's not giving proper result:

#include "Dataflash.h"
#include


uint8_t DF_CheckCorrectOnboardChip(void)
{
	
        DDRC = 0xff;
        DDRF = 0xff;

	DF_WaitWhileBusy();
	
	if (((SPI_SPITransmit(0x00) & DF_DFINFOMASK)) != DF_AT45DB041B_DENSITYMASK)
	{
		while(1)
		{
			PORTC = 0xff;
			_delay_ms(1000);
			PORTC = 0x00;
			_delay_ms(1000);
		}
				
		return FALSE;
	}
	else
	{
		while(1)
		{
			PORTF = 0xff;
			_delay_ms(1000);
			PORTF = 0x00;
			_delay_ms(1000);
		}
		
		return TRUE;
	}
}

void DF_WaitWhileBusy(void)
{
	DF_TOGGLEENABLE();
	
	SPI_SPITransmit(DFCB_STATUSREG);
	
	while (!(SPI_SPITransmit(0x00) & DF_BUSYMASK));
}


#define  INC_FROM_MAIN
#include "Main.h"

#include


int main(void)
{	
	
        PRR0     = ((1 << PRADC) | (1 << PRSPI));	  
        DDRB    = ((1 << 0) | (1 << 1) | (1 << 2));
	PORTB   = ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
	
	
	DF_CheckCorrectOnboardChip();
		
}

Would anybody can give any suggestions?

Thanks,
Chotan

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the AVR butterfly has a dataflash. You could search for its source code and use that to read/write your dataflash.

Without checking the datasheet:
is WP positive or negative logic? you make the line high, can it be that the dataflash is locked doing that??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

You could search for its source code and use that to read/write your dataflash.


Or search for posts I've made here containing "dflash.c" which are my own AT45 routines.

BTW when working with AT45 I found it invaluable to have a scope to check SCK/MOSI/MISO activity and verify that it was as expected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You're also going to need a filesystem driver on top of the Dataflash routines - check out the "TempDataLogger" project in the LUFA Projects directory for a full example that logs the current temperature to the dataflash, and allows the host to view it in CSV format later on.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your response and sharing the routines. I was trying "dflash.c", "Dataflash.zip" and "TempDataLogger". Better to concentrate one first.

In "TempDataLogger" I have changed the makefile and if I change the BOARD = NONE then I'm getting errors like

    ../../LUFA/Drivers/Board/Dataflash.h:225:6: error: #error The Board Dataflash driver cannot be used if the makefile BOARD option is not set. ../../LUFA/Drivers/Peripheral/AVR8/TWI_AVR8.h: In function 'TWI_Init':
    ../../LUFA/Drivers/Peripheral/AVR8/TWI_AVR8.h:208:5: error: 'TWCR' undeclared (first use in this function)

And if I keep BOARD = USBKEY then I'm getting errors like

    ../../LUFA/Drivers/Peripheral/AVR8/TWI_AVR8.h: In function 'TWI_Init': ../../LUFA/Drivers/Peripheral/AVR8/TWI_AVR8.h:208:5: error: 'TWCR' undeclared (first use in this function)

How can I eliminate these?

Thanks,
Chotan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The logging application expects a I2C RTC chip to be attached for timekeeping, so that the written files can be updated with the correct timestamps. If you don't need that or are using a device without I2C support, you can compile the demo with "-D USE_DUMMY_RTC".

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My device is not supporting 12C so I have changed

#LUFA_OPTS += -D DUMMY_RTC to
LUFA_OPTS += -D USE_DUMMY_RTC

Should I comment off all the statements of "DS1307" and "TWI", cause still I have some errors.

/Chotan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Whoops, uncomment (remove the #) the DUMMY_RTC line in the makefile - I mis-remembered it as "USE_DUMMY_RTC".

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I have done this, but I'm getting errors in "DS1307" and "TWI", so shall I comment off all these statements.

/Chotan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No luck to change the ds1307 and twi codes. If I want to use BOARD = NONE what I have to remove? Any suggestions?

/Chotan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you want to use BOARD = NONE, how would the demo know how to read the temperature sensor? If you set BOARD = NONE in the makefile, you will need to remove all includes of the board driver headers, and remove all references to the board driver APIs in the code.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!