I'm attempting to use the arduino as an ICSP AVR to flash hundreds of ATMEGA's 90USB162. I'm having some difficulties when trying to do the actual flashing of the chip. I've go all the wires done properly and I'm able to read the signature. My source is an Intel hex file and I'm reading it properly as I'm able to see each by as it is read from the arduino's memory. Where I'm getting lost is the documentation states that I need to set the low byte first before I set the high byte for the same memory address. Using the following as an example (underscores to break the data up) could someone help me descern what my SPI transaction bytes would look like?
:_20_0000_00_16C100003CC100003AC1000038C1000036C1000034C1000032C1000030C10000_48
I know the colon is the start code, 20 is the hex value of number of data bytes, 0000 is the address, 00 is the record type, the next 32 bytes is my data followed by the checksum.
I thought that I would loop over the data portion and increment the address every other byte
uint16_t addr = 0;
while (recordtype != endOfFile)
{
auto data[] = parseData();
for(uint8_t index = 0; index < 32;)
{
SPITask.Send(0x40, 0x00, addr, data[index++]);//send low byte
SPITask.Send(0x48, 0x00, addr, data[index++]);//send high byte
SPITask.Send(0x4C, addr, addr, 0x00);//commit new bytes to address
addr++;
}
}
I don't think this is right and some examples i'm loosely following comment that they are changing the address byte into a word, which makes some sense based on the command layouts of the data sheet (page 260) 90USB162 Data sheet. Can anyone please provide some guidance in how to break up this data into high and low bytes.