 
					
				
		
Hi,
I am making a software to write into LPC1767, I have four questions
Code
if (serialport.IsOpen)
 {
 #region Attempt 2
 {
serialport.Write("?");
 string responseSync = "Synchronized\r\n";
 readWait(responseSync.Length);
 string result = serialport.ReadExisting();
 readTextBox.Text += result + System.Environment.NewLine;//sync by reader
// Synchronized OK
 if (result.Equals(responseSync))
 {
 string w1 = "Synchronized\r\n";
 serialport.WriteLine(w1);
 string r1 = "OK\r\n";
 readWait(r1.Length);
 Thread.Sleep(50000);
string r2 = serialport.ReadExisting();// OK by reader <--------- ISSUE IS HERE I DON'T GET "OK" instead i get //random chars
readTextBox.Text += "Check if sync ok" + System.Environment.NewLine;
 readTextBox.Text += r2 + System.Environment.NewLine;
//crystal frequency
 if (r2.Equals(r1))
 {
 //send crystal frequency
 string crystalFrequency = "12000\r\n";
 //host now send crystal frequency
 serialport.Write(crystalFrequency);
 //wait for reciever to sent OK
 readWait(r1.Length);//wait after OK
 string readCrystalFrequencyOk = serialport.ReadExisting();//will read response OK
 readTextBox.Text += readCrystalFrequencyOk + System.Environment.NewLine;
 if (readCrystalFrequencyOk.Equals(r1))
 {
 readTextBox.Text += "Crystal Frequency sent" + System.Environment.NewLine;
readTextBox.Text += "Closing SerialPort after initial commands" + System.Environment.NewLine;
 serialport.Close();
 }
 }
 }
}
4. This is the UU-encoded data which will be written later on device, The issue is the first 512 bytes checksum is valid according to "AN" NXP doc, but after sniffing data from flashmagic the first 512 bytes are invalid as they are 35644.
Help will be appreciated, Thank you in advance.
Regards,
M.Bilal
 
					
				
		
 xiangjun_rong
		
			xiangjun_rong
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hi, Muhammad Bilal,
Q1:My first question is , do we need to erase flash every time after its been written? or does it get overwritten after writing on it for second time? and for only erasing flash do we need initial handshaking i.e ?,synchronized\r\n,crystal frequency?
>>>>>>>Yes, the on-chip flash of LPC17xx is NOR flash, you have to erase the flash every time before you program it. Ersaing flash makes all flash data in 0xFF(all bits in flash are ONE), programing flash can make the bits to 0 or keep to 1. I do not think you need any synchronization or crystal setting when you erase/program flash.
Q2:Does the LPC1767 micro controller always enter ISP mode after connecting cable, I read what is said in "UM" but i didn't get it.
>>>>>>>>>>>>>>>Whether the LPC17xx enters ISP mode or user application code is dependent on the P2.10 pin logic during/after Reset, when the pin is logic 0 by a pull-down resistor during/after Reset, the chip enters to execute user application code. When the pin is logic high by a pull-up resistor during/after Reset, the chip enters ISP mode.
Q3:This is my c# code for initial handshaking but after sending "Synchronized\r\n", we get invalid characters such as "?", "/","o" etc from reader instead of "OK" so that i can give crystal frequency next. I am following "UM" document by NXP. what might be the issue here?
>>>>>>>>>>>>>>>I suppose that the baudrate of uart does not match, which leads to the issue, pls check you code on both PC and the LPC sides.
Hope it can help you
BR
Xiangjun rong
