NXP LPC 810 mini kit, try to build my own ISP software


 

FlashMagic 很好, 只是有問題時, 看不到太多DEBUG資訊, 太多選項, 不方便測試

lpc21isp 不能用, 作者因為沒有 PORT 給 lpc810 用, 連線都不成

所以試試看, 能不能自己寫一個陽春版, 看看 lpc 的 ISP 運作順序

my_lpc810isp

 

用免費的工具 GCC 編譯

RS232 library 是上次用過的那個, 作者最近又新版本, 所以用新的

修改一下就可以用, 如何編譯重溫這篇

NXP LPC810 mini kit 看這篇

編好的 windows 可執行程序不能放在BLOG, 需要找別的地方, GIT 忘記怎樣用了….

源碼, 確定可以, 固定用COM4, 9600BAUD


/**************************************************

orginal code example, http://www.teuniz.net/RS-232/

file: main.c
purpose: simple demo that receives characters from
the serial port and print them on the screen

modification : NXP lpc810 ISP communication and test
xiaolaba 2013-06-24

**************************************************/


#include <stdlib.h>
#include <stdio.h>

#include <string.h>

#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif

#include "rs232.h"



int main()
{
//http://www.programiz.com/c-programming/c-strings
//ref, how to used char and string as array, null terminated
char sync[2]      = "?";    // lpc810, initial sync command
char synced[14+1] = "Synchronized\r\n";    // lpc810, sync command

char clock_speed[7+1] = "12000\r\n";    // lpc810, clock speed command
char J[3+1] = "J\r\n";    // lpc810, read part ID command
char K[3+1] = "K\r\n";    // lpc810 read boot code version command
char N[3+1] = "N\r\n";    // lpc810 read UID command

int n,
//cport_nr=0,      // /dev/ttyS0 (COM1 on windows)
cport_nr=3,        // /dev/ttyS3 (COM4 on windows), my USB COM port
bdrate=9600;       // 9600 baud

unsigned char buf[4096];

char state;    // state machine variable for lpc810 ISP commmnuncation


printf("Try to read LPC810 device ID and UID\r\n");
printf("REF : http://www.teuniz.net/RS-232/\r\n");
printf("xiaolaba 2013-06-24, copy right\r\n\r\n");


if(RS232_OpenComport(cport_nr, bdrate))
{
printf("Can not open comport\n");

return(0);
}


state = 'A';    // start of state machine, not a null string

RS232_cputs(cport_nr, sync); // send first sync char to LPC810, initiate communication


while(1)
{
n = RS232_PollComport(cport_nr, buf, 4095);

if(n > 0)
{
buf[n] = 0;   // always put a "null" at the end of a string!
/*
for(i=0; i < n; i++)
{
if(buf[i] < 32)  // replace unreadable control-codes by dots
{
buf[i] = '.';
}
}
*/

printf("state machine = %c\r\n", state);

printf("received %i bytes:\r\n%s\r\n", n, (char *)buf);    //display COM port incoming data, echo back or sent by lpc810

//http://www.cchsu.com/arthur/prg_bg5/c/4.7.htm
//ref, how to use switch/case in C
switch (state)
{
case 'A': RS232_cputs(cport_nr, sync); state++; printf ("\r\n"); break;  // lpc810 sync
case 'B': RS232_cputs(cport_nr, (char *)buf); state++; printf ("\r\n"); break;  // lpc810 sync
case 'C': RS232_cputs(cport_nr, synced); state++; printf ("\r\n"); break;  // lpc810 synced
case 'D': RS232_cputs(cport_nr, clock_speed); state++;
printf("lpc810, clock set to 1200KHZ\n");
break;  // lpc810 RC clock, 12000 HKZ, 12MHZ
case 'E': RS232_cputs(cport_nr, J); state++;
printf("lpc810, Part ID (DECIMAL)\n");
break;  // read lpc810 part ID
case 'F': RS232_cputs(cport_nr, K); state++;
printf("lpc810, boot code version\n");
break;  // read lpc810 boot code version
case 'G': RS232_cputs(cport_nr, N); state++;
printf("lpc810, UID\n");
break;  // read lpc810 UID

default :          break;
}


}

#ifdef _WIN32
Sleep(100);       //sleep 100ms
#else
usleep(100000);  // sleep for 100 milliSeconds
#endif
}


return(0);
}



廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s