Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
Posted: Fri Sep 05, 2014 8:12 am Post subject:
Hi,
The i2c bootloader code is now finished. I left it running over night uploading various version of the main app/testing the functions in the slave and the upload ran 600times without any errors.
So, here's the code:-
Upload routine for the main CPU
Code:
'----------------------------------------------------------------------------- Sub Upload_firmware(byval I2c_address AsByte) 'Function : Send firmware image to uC 'Author : Ian Dobson 'Inputs : Write address of slave. 'Outputs : None 'Limitations : The pointer to the firmware to upload must be set before ' calling this routine (using restore) ' The firmware should be included using the $inc command with ' the size option. For example ' $inc Irda_firmware , Size , "SlaveFirmware.bin" ' ' The routine sends 64 bytes plus 2 leading bytes (Block type and ' Block number) 'Date : 5.9.2014 Dim Pointer AsWord Dim Page_write AsWord Dim Flash_byte AsByte Dim Block_nr AsByte Dim Sync AsByte Dim I2c_address_read AsByte Dim Data_block(65)AsByte
I2c_address_read = I2c_address +1 Read Irda_fw_size
Irda_fw_size = Irda_fw_size +2 Print #1 , "IRDA FW Size="; Irda_fw_size
Pointer =0
Block_nr =0 While Pointer < Irda_fw_size
Chksum =0
Sync = My_nack 'Sync not OK For Page_write =1To64'Build Packet array If Pointer <= Irda_fw_size Then Read Flash_byte
Data_block(page_write)= Flash_byte 'read FW from flash Else
Data_block(page_write)=&HFF 'pad to 64 bytes End If Incr Pointer
Next Page_write
While Sync <> My_ack 'Do until block OK I2cstart'setup i2c bus I2cwbyte I2c_address 'request slave I2cwbyte123'Block Type I2cwbyte Block_nr 'Block number For Page_write =1To64'Send 64 bytes I2cwbyte Data_block(page_write)'send byte Next Page_write
I2cstop'Release bus
Waitms5 I2cstart'setup i2c bus I2cwbyte I2c_address_read 'read slave I2crbyte Sync , Nack'Get Sync byte I2cstop'Release bus
If Sync = My_ack Then'Block OK? Print #1 , "."; Incr Block_nr 'Yes Else Print #1 , "!"; End If Waitms1'Wait abit Wend'Block OK loop Wend'Transfer finished loop
'Now send last Block all 0's I2cstart'setup i2c bus I2cwbyte I2c_address 'request slave I2cwbyte123 I2cwbyte Block_nr
For Page_write =1To64'64bytes I2cwbyte0'End CMD Next Page_write
I2cstop'Release bus
Waitms10 I2cstart'setup i2c bus I2cwbyte I2c_address_read 'read slave I2crbyte Sync , Nack'Get byte I2cstop If Sync = My_ack Then'Block OK? Print #1 , " OK" Else Print #1 , " "; Sync
End If Waitms1 EndSub
And the bootloader code is in the attachment.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen.
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 You cannot attach files in this forum You cannot download files in this forum