Content originally posted in LPCWare by Hareesha on Tue Mar 13 00:39:11 MST 2012
[COLOR=#000000][FONT=Verdana, serif]Hi Friends, I am here once again after long time.[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana, serif]Now I am able to read ASCII value in controller side by using UART0 through serial communication. Received buffer having data as follows[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana, serif]UART0Buffer[ ] = {:100000000080001029010000F5000000F70000004A…………………..}[/FONT][/COLOR]
[COLOR=#000000][COLOR=#00b050][FONT=Courier New, serif][SIZE=4][B]If my approach is wrong and if anybody knows better approach plz let me know. That is what to do after receives the data???.[/B][/SIZE][/FONT][/COLOR][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]For testing purpose I am doing as follow approaches.[/SIZE][/FONT][/COLOR]
[COLOR=#000000][COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]unsigned[/B][/SIZE][/FONT][/COLOR][COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]int[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2] UART0Buffer[2] = {0x001F,0x001E,0x001D,0x001C,0x001B,0x001A };[/SIZE][/FONT][/COLOR][/COLOR]
[COLOR=#000000][COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]int[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2] no_of_bytes = 512;[/SIZE][/FONT][/COLOR][/COLOR]
[COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]while[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2](!CMD_SUCCESS)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]{[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]write_flash(([/SIZE][/FONT][/COLOR][COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]unsigned[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2] *)sector_start_map[2],([/SIZE][/FONT][/COLOR][COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]char[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2] *)UART0Buffer,no_of_bytes);[/SIZE][/FONT][/COLOR]
[COLOR=#000000][COLOR=#000000][FONT=Courier New, serif][SIZE=2]}[/SIZE][/FONT][/COLOR][/COLOR]
[COLOR=#000000][COLOR=#ff0000][FONT=Courier New, serif][SIZE=3][B]BUT I am not able to write data into flash.[/B][/SIZE][/FONT][/COLOR][/COLOR]
[COLOR=#000000][FONT=Verdana, serif]And is there any wrong in approach and is it necessary to write block wise.[/FONT][/COLOR]
[COLOR=#000000][COLOR=#000000][FONT=Courier New, serif][SIZE=2]Standard flash write function is as follow [/SIZE][/FONT][/COLOR][/COLOR]
[COLOR=#000000][COLOR=#000000][FONT=Courier New, serif][SIZE=2]------[/SIZE][/FONT][/COLOR][/COLOR]
[COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]unsigned[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2][B]write_flash[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2]([/SIZE][/FONT][/COLOR][COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]unsigned[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2] * dst, [/SIZE][/FONT][/COLOR][COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]char[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2] * src, [/SIZE][/FONT][/COLOR][COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]unsigned[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2] no_of_bytes)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]{[/SIZE][/FONT][/COLOR]
[COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]unsigned[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2] i;[/SIZE][/FONT][/COLOR]
[COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]if[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2] (flash_address == 0)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]{[/SIZE][/FONT][/COLOR]
[COLOR=#3f7f5f][FONT=Courier New, serif][SIZE=2]/* Store flash start address */[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]flash_address = ([/SIZE][/FONT][/COLOR][COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]unsigned[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2] *)dst;[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]}[/SIZE][/FONT][/COLOR]
[COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]for[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2]( i = 0;i<no_of_bytes;i++ )[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]{[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]flash_buf[(byte_ctr+i)] = *(src+i);[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]}[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]byte_ctr = byte_ctr + no_of_bytes;[/SIZE][/FONT][/COLOR]
[COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]if[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2]( byte_ctr == FLASH_BUF_SIZE)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]{[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]find_erase_prepare_sector(SystemCoreClock/1000, ([/SIZE][/FONT][/COLOR][COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]unsigned[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2])flash_address);[/SIZE][/FONT][/COLOR]
[COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]if[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2](result_table[0] != CMD_SUCCESS)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]{[/SIZE][/FONT][/COLOR]
[COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]while[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2](1);[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]}[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]write_data[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2](SystemCoreClock/1000,([/SIZE][/FONT][/COLOR][COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]unsigned[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2])flash_address,([/SIZE][/FONT][/COLOR][COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]unsigned[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2] *)flash_buf,FLASH_BUF_SIZE);[/SIZE][/FONT][/COLOR]
[COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]if[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2](result_table[0] != CMD_SUCCESS)[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]{[/SIZE][/FONT][/COLOR]
[COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]while[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2](1); [/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2]}[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]byte_ctr = 0;[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]flash_address = 0;[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]}[/SIZE][/FONT][/COLOR]
[COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]return[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2](CMD_SUCCESS);[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]}[/SIZE][/FONT][/COLOR]
[COLOR=#000000][COLOR=#000000][FONT=Courier New, serif][SIZE=2]-----------[/SIZE][/FONT][/COLOR][/COLOR]
[COLOR=#000000][COLOR=#000000][FONT=Courier New, serif][SIZE=2]Otherwise shall I follow directly as follow,[/SIZE][/FONT][/COLOR][/COLOR]
[COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]unsigned[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2] * flash_address = 0;[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]flash_address = 0x2000;[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]# define FLASH_BUF_SIZE = 512;[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New, serif][SIZE=2]write_data(SystemCoreClock/1000,([/SIZE][/FONT][/COLOR][COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]unsigned[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2])flash_address,([/SIZE][/FONT][/COLOR][COLOR=#7f0055][FONT=Courier New, serif][SIZE=2][B]unsigned[/B][/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Courier New, serif][SIZE=2] *)UART0Buffer,FLASH_BUF_SIZE);[/SIZE][/FONT][/COLOR]
[COLOR=#000000][COLOR=#000000][FONT=Courier New, serif][SIZE=2]--------[/SIZE][/FONT][/COLOR][/COLOR]