Hi!
I have already created the firmware for Lpc1114 but an issue I am running into is how to communicate with the mcu through a GUI. I know how to create gui's but I don't know how to send binary that then gets converted to a USB packet and then to the UART port of the mcu. Any suggestions would be helpful.
One way is to buy a USB to Uart Converter. I found Trendnet brand to be inexpensive on ebay. something like $4 dollars to $7 dollars.
I create gui s using Embarcadero C++ Builder for windows. Although that is expensive to buy. Then You can program the serial port with standard programs. I am not very good with visual studio when it comes to guis. But the Serial Port Programming is the same for it also. You can also just program using console programs if you want to.
Oh ok I have never made a GUI for microcontrollers before so I wasn't sure at all about where to start. So once I make the GUI I just program the serial ports and with the usb to UART cable it should work?
Some advice. Places like ebay are full of counterfeits when it comes to usb/serial devices. Finding genuine FTDI parts is a particular problem nowadays.
I've recently discovered the CP2102. Do a search for that. They work reliably, the drivers work reliably, they work with Windows and Linux (and quite a few Android apps). They provide all signals, they can supply both 3.3V and 5V. And they're cheap as chips. I buy them in bulk and use them for all sorts of projects.
Here's an example:
www.ebay.com/.../400565980256
First you need to decide on a compiler to use and a Language C/C++ or C#.
There are some example programs you can find on the web. I choose C/C++ language for me. I would start off by writing a console program to test out the basic functions of the program. Connect a RS232 adapter and put a 9 pin connector to short pins 2 and 3 together so you can test your program without a board.
You will have to know the com port that the adapter is running on and you will need to configure baud rate, num of stop bits ect. you can use device manager to see where the adapter comport is located at.
I think you will need to buy a adapter that has RS232 voltage levels. I was wrong about the prices of the trend net adapters thwy appear to be around 14.00.
I think you will need to buy a adapter that has RS232 voltage levels.
That does, of course, depend on the hardware; and we don't know the detail of it.
I've used the CP2102 with direct connections to the LPC1114. No problems.
I think Teraterm a terminal program is capable of sending binary data if you choose the advanced option to send a file. That way you can try to send binary data that ha a smaller learning curve
Here is some code I wrote not complete but may give you an Idea.
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "SER_TST_JUN4.h" #include "math.h" #include "conio.h" #include "iostream.h" #include <iomanip> #include <fstream> HANDLE m_hCom; char m_sComPort[10]; BOOL m_bPortReady; DCB m_dcb; COMMTIMEOUTS m_CommTimeouts; BOOL bWriteRC; BOOL bReadRC; int indx_list[20]; int length_list[20]; unsigned char str2[4000]; char STRING_OUT[4000]; int i, j; DWORD iBytesWritten; // READ STUFF DWORD iBytesRead; unsigned char sBuffer[10000]; char message[4000]; int CMD_NUM = 1; //int complete_num; void open_port(); void close_port(); void send_cmd(int index, int length); void receive_cmd(int length); void load_array(); void INIT_LONG_ARRAY(); void send_long_cmd(int index, int length); void receive_long_cmd(int length); unsigned char A_arr[] = { 0x11, 0x22, 0x3C, 0x1E, 0x10, 0x22, 0x33, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11 }; unsigned char * ptr; //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TForm1::send_buttonClick(TObject *Sender) { length_list[0] = 10; indx_list[0] = 0; memset(STRING_OUT, 0x00, 100); memset(str2, 0x00, 200); load_array(); open_port(); send_cmd(indx_list[0], length_list[0]); receive_cmd(length_list[0]); close_port(); } //--------------------------------------------------------------------------- void send_cmd(int index, int length) { bWriteRC = WriteFile(m_hCom, &str2[index], length, &iBytesWritten, NULL); return; } void load_array() { ptr = A_arr; //ptr = B_arr; //ptr = C_arr; //ptr = D_arr; //ptr = E_arr; indx_list[0] = 0; //begining index of command length_list[0] = 23; // length of command str2[0] = ptr[0]; str2[1] = ptr[1]; str2[2] = ptr[2]; str2[3] = ptr[3]; str2[4] = ptr[4]; str2[5] = ptr[5]; str2[6] = ptr[6]; str2[7] = ptr[7]; str2[8] = ptr[8]; str2[9] = ptr[9]; str2[10] = ptr[10]; str2[11] = ptr[11]; str2[12] = ptr[12]; str2[13] = ptr[13]; str2[14] = ptr[14]; str2[15] = ptr[15]; str2[16] = ptr[16]; str2[17] = ptr[17]; str2[18] = ptr[18]; str2[19] = ptr[19]; str2[20] = ptr[20]; str2[21] = ptr[21]; str2[22] = ptr[22]; str2[23] = ptr[23]; ///--------------------------------- return; } void open_port() { strcpy(&m_sComPort[0], "Com1"); m_hCom = CreateFileA(m_sComPort, GENERIC_READ | GENERIC_WRITE, 0, // exclusive access NULL, // no security OPEN_EXISTING, 0, // no overlapped I/O NULL); // null template m_bPortReady = SetupComm(m_hCom, 1000, 1000); // set buffer sizes // Make a call to GetCommState() first in order to fill // the comSettings structure with all the necessary values. // Then change the ones you want and call SetCommState(). m_bPortReady = GetCommState(m_hCom, &m_dcb); m_dcb.BaudRate = 115200; //9600; //921600; //9600; m_dcb.ByteSize = 8; m_dcb.Parity = NOPARITY; m_dcb.StopBits = TWOSTOPBITS; m_dcb.fAbortOnError = TRUE; m_bPortReady = SetCommState(m_hCom, &m_dcb); m_bPortReady = GetCommTimeouts (m_hCom, &m_CommTimeouts); m_CommTimeouts.ReadIntervalTimeout = 50; m_CommTimeouts.ReadTotalTimeoutConstant = 50; m_CommTimeouts.ReadTotalTimeoutMultiplier = 10; m_CommTimeouts.WriteTotalTimeoutConstant = 50; m_CommTimeouts.WriteTotalTimeoutMultiplier = 10; m_bPortReady = SetCommTimeouts (m_hCom, &m_CommTimeouts); return; } void receive_cmd(int length) { memset(sBuffer, 0x00, 10000); bReadRC = ReadFile(m_hCom, &sBuffer, length, &iBytesRead, NULL); memset(STRING_OUT, 0x00, 100); memset(message, 0x00, 40000); sprintf(message,"%d ", CMD_NUM ); strcat(STRING_OUT, message); CMD_NUM = CMD_NUM + 1; for(j = 0; j <= length-1; j++) { sprintf( message,"%x ", sBuffer[j] ); strcat(STRING_OUT, message); //ShowMessage(STRING_OUT); } Form1->ListBox1->Items->Add(STRING_OUT); return; } void close_port() { CloseHandle(m_hCom); return; } //--------------------------------------------------------------------------- void __fastcall TForm1::rcv_buttonClick(TObject *Sender) { length_list[0] = 10; indx_list[0] = 0; memset(STRING_OUT, 0x00, 100); memset(str2, 0x00, 200); //load_array(); open_port(); //send_cmd(indx_list[0], length_list[0]); receive_cmd(length_list[0]); close_port(); } //--------------------------------------------------------------------------- void __fastcall TForm1::sendchar_buttonClick(TObject *Sender) { length_list[0] = 1; indx_list[0] = 0; memset(STRING_OUT, 0x00, 100); memset(str2, 0x00, 200); str2[0] = 'a'; open_port(); send_cmd(indx_list[0], length_list[0]); close_port(); } //--------------------------------------------------------------------------- void send_long_cmd(int index, int length) { char messge[100]; messge[0] = NULL; bWriteRC = WriteFile(m_hCom, &STRING_OUT[index], length, &iBytesWritten, NULL); sprintf(messge,"written = %d ", iBytesWritten); ShowMessage(messge); return; } void receive_long_cmd(int length) { char messge[100]; messge[0] = NULL; memset(sBuffer, 0x00, 4000); bReadRC = ReadFile(m_hCom, &sBuffer, length, &iBytesRead, NULL); memset(STRING_OUT, 0x00, 4000); memset(message, 0x00, 4000); sprintf(message,"%d %d", CMD_NUM, iBytesRead ); strcat(STRING_OUT, message); CMD_NUM = CMD_NUM + 1; for(j = 0; j <= length-1; j++) { sprintf( message,"%x ", sBuffer[j] ); strcat(STRING_OUT, message); //ShowMessage(STRING_OUT); } Form1->ListBox1->Items->Add(STRING_OUT); fstream outfile("out.txt", ios::out); outfile << STRING_OUT << endl; outfile.close(); sprintf(messge,"j = %d \t %d", j, length); ShowMessage(messge); return; }
Wow ok thanks a lot for all the help this is more help than I thought I would receive, I know what I need to do now. Thanks again!