DrBug
DrBug

Reputation: 2024

AVR Assembly - store port data in program flash

Can someone point me to a good tutorial that explains storing data in program flash for Atmega 328P ? I am planning to receieve 8 bit data from portB at 1 Mhz frequency and I want to store first 19200 bytes of data recieved in program flash which has 32k memory. I am new to AVR assembly and I am a bit confused after reading all that I could google, so a direct answer or some good tutorial to read would be greatly appreciated.

As of now I have coded it as

LDI XL, LOW(NRWW_START_ADDR)
LDI XH, HIGH(NRWW_START_ADDR)
loadBuffer:
IN R0,PORTB
ST X+,R0
CPI XH,0x4B
BRNE loadBuffer

But I am not sure if this is the correct thing to do. I would like not to overwrite the bootloader. Also, I am looking for a solution in assembler.

Any help or pointer is much appreciated.

Upvotes: 0

Views: 1792

Answers (1)

uhum2004
uhum2004

Reputation: 11

Two notes:

  1. You're making a common mistake in this example: shuffling input and output on the same port. If you want to read from the B port, then you have to read PINB; if you want to write to it, you must write to PORTB. (Assuming DDRB was set before.)

  2. Are you sure you want to use flash memory for data storage? Data sheet says:

    Write/Erase Cycles: 10,000

Upvotes: 1

Related Questions