I want to interface MCB2140 with a pressure sensor which will give input for every 1 second.. I connected UART0 to pressure sensor output, UART1 to serial port of PC. The pressure sensor gives the integer value as output.The UART0 will receive data from sensor and should display in hyper terminal for every 1 minute..I wrote the following code..The code gets hanged in startup file at BX R0...Please let me know any other changes required #include <LPC21xx.H> void init_serial (void); int main(void) { init_serial();
while(1) { int getc_serial0; int putc_serial1; } } void init_serial (void) {
PINSEL0 = 0x00050005;
U0LCR = 0x00000083;
U0DLL = 98;
U0LCR = 0x00000003;
U1LCR = 0x00000083;
U1DLL = 98;
U1LCR = 0x00000003;
}
int getc_serial0(void)
{
while (!(U0LSR & 0x01));
return U0RBR;
} int putc_serial1(void)
while (!(U1LSR & 0x20));
U1THR=U0RBR;
return (U1THR);
And then what will happen...?!
"i removed while(1) loop"
Why?
What do you think that will achieve?
main() { init_serial(); getc_serial0(); putc_serial1(); }
Do you not believe in indentation when you write source code?
Do you not think this is easier to read:
main() { init_serial(); getc_serial0(); // What is the point of this call? putc_serial1(); // What is the point of this call? }
What will happen when main() returns...?
Wait a minute. Your original error description was "The code gets hanged in startup file at BX R0".
Do you not mean that it hangs on startup, but that it does enter main() and then after a while fails? Always (!) write clear enough error descriptions that people who read them can understand what problems you are having.
If the program do reach main(), but then the obvious question is if you have tried to step through your code to getIn that case - haven't you checked how many source lines you can step through before you get an exception? Haven't you tried my previous advice: "Have you tried breakpoints for the exception handlers?"
A main loop without a loop is obviously an epic failure. There is no command line or GUI desktop to get back to when your application ends. So don't let your programs end until you build large enough embedded systems that you really do have a GUI program manager or a command line (Linux, Win CE, ...)
Please let me know any problem is there in the code which i posted earlier. I don't know what is going on in the code. I am new to the embedded field. Please rather than asking me can anyone exactly tell the reason why it is not working.
It doesn't matter how new you are to embedded.
1) You just have to learn to debug. Therea are no alternatives, since people on web forums will not copy/paste code just to debug for you.
2) You have received multiple comments about your strange plays with your get/put functions. In the first code you didn't do any calls at all. In the second sets of code you don't do what you should - return a byte from getc() and send a byte to putc(). You somehow thinks putc() should copy data between two SFR which is the wrong thing to do.
3) Being new to something means a large need to read. What have you been reading? The datasheet for your processor? Don't assume that a transmit holding register (used for writing data to a serial port) is a register that can also be read. Exactly what do you think it will return? If the receive and transmit registers where actually the same thing - wouldn't the processor just have a "data register" then? And for a processor that can cache multiple outgoing bytes - which byte should the transmit holding register then return? And what if the transmitter is empty - what should the transmit holding register then return?
Lots of questions in my text? Yes. Why? Because you need to see for yourself that you are making assumptions. To assume is sometimes spelled ass-u-me because assumptions is the best way to do something wrong. Assumption is just a "finer" word for "guessing". Datasheets, user manuals, application notes, sample code packages etc are there so that developers will not have to guess.
Remember that I - and everyone else on this forum - are regularly new to different processors. But we can't then write random code lines and ask on a forum why the lines doesn't work. We have to read until we find text sections that tells us what is needed to get data from a serial port. Or for sending data to a serial port. Or asking if data is available. Or the transmitter have room for more data. Or how to set the correct baudrate.
Experience just means we better knows what terms to scan for in the manuals. And that we are quicker at "guessing" where to put breakpoints in the code - or trace output - to compare what really happens with what was intended to happen.
"Please let me know any problem is there in the code which i posted earlier"
Plenty of problems have been pointed out to you already.
"I don't know what is going on in the code. I am new to the embedded field"
So, before just charging into writing code, don't you think you should spend some time studying & learning first?
If you wanted to learn to swim, would you just jump off a ship in the middle of the ocean...?
There are book suggestions here: http://www.keil.com/books/
Seminars here: http://www.keil.com/events/
Training providers here: http://www.keil.com/events/links.asp
etc, etc,...
But a discussion forum such as this cannot give you a full training course in embedded development!
"Please rather than asking me can anyone exactly tell the reason why it is not working"
But you need to lay the basic foundations before you will understand the explanations!
You have two choices here:
1. Spend time (possiby also money) to learn about embedded development;
2. Pay someone to do this for you...
Hi Andrew neil, So for learning the embedded coding i have to come from india to USA or other countries to attend seminars. I think this is the costliest suggestion to learn embedded development in total forum. Please do not make fun of the guys who are new to embedded development in future atleast.. Here all other profiles (like per westermerk, etc... ) are giving good suggestions, but your's is the only bad suggestion
Not at all!
I'm sure there are plenty of good training providers in India.
www.lmgtfy.com
">http://www.keil.com/events/ link that I gave you, the Design Strategies for ARM Systems series is being prsented worldwide:
http://www.keil.com/events/seminar/222.htm
Dates for Asia: www.em.avnetasia.com/.../
This is just one series from just one distributor - there must be plenty more...
"I think this is the costliest suggestion"
The cheapest solution is not necessarily the most effective - nor the best value
"Please do not make fun of the guys who are new to embedded"
I'm not making fun of anyone; just pointing out that learning embdedded development requires a significant commitment and investment - in time, or money, or both.
Note also that there is much more to embedded development than just "coding".