MC52235 Serial Port Communications

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MC52235 Serial Port Communications

4,447 次查看
coco3811
Contributor I
Hi, I am just starting out so I would really appreciate some help. I am trying to write some simple code for the 52235CAL60. Basically I am trying to just send data from the computer to the board and either send it write back to the computer (displayed in hyperterminal) or modify it slightly such as capitilize it, etc. Any help would be greatly appreciated. Thank you.
标签 (1)
0 项奖励
20 回复数

1,316 次查看
schogun
Contributor I

Hi Coco3811...
 

I have got the same problem. I am trying to send data from the board to the com-port.

I am working with MFC52235EVB. Did you find any solution for the undefined error problem?


Best Regards

T. Schmidt

0 项奖励

1,316 次查看
coco3811
Contributor I
Not yet but I'll keep you updated
0 项奖励

1,316 次查看
JimDon
Senior Contributor III
  First of all I will assume that you are using CW for CF V7.0.

- Creat a new project, but make sure in the first dialog, you pick "Cold Fire Evaluation Boards"/"Coldfire V2"/ Your eval board. Under connection pick P&E.

- On the next dialog pick set up the name/path you want.

- Pick None on the Rapid Application dialog.

- Leave the next dialog as it is - Full Board Support, Easy Debug.

Click finish.

Use the INTERNAL_RAM   NOT the CONSOLE  target.

Paste this into main. Start a terminal emulator 19200, 8 bit, no flow control.

Code:
#include "support_common.h" /* include peripheral declarations and more */
// Change this line for your board
#include "M52223EVB_sysinit.h"
#include "uart_support.h"

#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT)
/* Standard IO is only possible if Console or UART support is enabled. */
#include <stdio.h>
#endif

int main(void)
{
 int counter = 0;
 volatile char c;
 uart_init(TERMINAL_PORT, SYSTEM_CLOCK_KHZ, TERMINAL_BAUD);
#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT)
 printf("\n\rM52223EVB board\n\r");
// fflush(stdout);
#endif
 
 for(;;) {   
   counter++;
   c = uart_getchar (TERMINAL_PORT);      // Read a character.
   uart_putchar (TERMINAL_PORT, c);       // echo it.

 }
}


 




Message Edited by JimDon on 2008-06-10 11:05 AM
0 项奖励

1,316 次查看
coco3811
Contributor I
How do I define TERMINAL_PORT, SYSTEM_CLOCK_KHZ, TERMINAL_BAUD?
 
0, 60000, 19200?
 
Code:
c = uart_getchar (TERMINAL_PORT);      // Read a character.   uart_putchar (TERMINAL_PORT, c);       // Echo it.

 
With the above code, the output of getchar is a char and the parameter for putchar is an int so won't this cause problems?
 
Also, I am still getting:
 
Link Error: Undefined: "uart_getchar"
Reference from "main" in main.c
 
for all 3 uart methods..


Message Edited by coco3811 on 2008-06-10 05:01 PM
0 项奖励

1,316 次查看
JimDon
Senior Contributor III
You don't define anything - the code should build and run as is.

Did it not?

It is normal in "C" to put char in ints. The code should build with 0 warnings as is.

0 项奖励

1,316 次查看
coco3811
Contributor I
No i'm still getting Link Errors and errors for TERMINAL_PORT, SYSTEM_CLOCK_KHZ, TERMINAL_BAUD. It doesn't make any sense because I see that these are defined in MCF52233_sysinit.h which I have included..There must be a problem with the linking of that file..Do you know how to resolve the linking problem?
0 项奖励

1,316 次查看
JimDon
Senior Contributor III
I sent you a pm with I my email. Send me the project zipped.
Change the extension to .zi_

0 项奖励

1,316 次查看
JimDon
Senior Contributor III
In support_common.h change this an it will build:

Code:
/* Enable UART Support. */#define ENABLE_UART_SUPPORT  1

 For some reason, mine came up as 1, yours did not.

Tell me if it works.




Message Edited by JimDon on 2008-06-10 01:22 PM
0 项奖励

1,316 次查看
coco3811
Contributor I
Ah, I'm surprised that it defaults to 0 and not 1.. I can get it to compile if I use the respective values 0, 60000, 19200 for the values in uart_init but if I put in the names it says they are undefined..
 
Also, when I run the program (with the numbers it will run), and open HyperTerminal connecting using COM1, 19200 Baud rate, 8 data bits, no parity, 1 stop bit and no flow control I don't get anything.
0 项奖励

1,316 次查看
JimDon
Senior Contributor III
That because you did not enter the code as I showed it.
I showed :

Code:
#include "support_common.h" /* include peripheral declarations and more */// Change this line for your board#include "MCF52233_sysinit.h" #include "uart_support.h"

 You decided to use instead:

Code:
#include "MCF52233_sysinit.h" #include "uart_support.h" #include "support_common.h" /* include peripheral declarations and more */

In the future, when someone posts code first try a cut and paste of it.
Also, #define ENABLE_UART_SUPPORT  1 was how it was orginally defined. You changed it, or did not generate the project as I asked. (I know because I just generated a project for  M52233DEMO - I gave you detailed steps to generate a project so this would not happen).

I can tell you did not do as I instructed. Please go generate a project for your BOARD using board support.
You generated the project for the chip, but not your board. (I can tell because in your project it has MCF52233_sysinit.h NOT M52233DEMO_sysinit.c or what ever the name of your board is).

I went to the trouble of giving you detailed steps, now you could at least take the time to follow them. If you had followed them it would have built right off the bat.



Order of includes is very important.
BTW There is good chance that is why it is not working.


As for your problem with hyper term, it could be many things. I don't have your board, so I can only give a clue.

Things to check:

Proper cable - should NOT be a null modem cable.
Jumpers on the board. I don't have your board, so you will just have to figure this out. Read the docs.
Correct connector on the board - mine has 3 serial ports. should use UART0.
Correct serial port on PC.
No other program using that serial port.

And perhaps other  things I have not thought of.


 










Message Edited by JimDon on 2008-06-10 03:07 PM
0 项奖励

1,316 次查看
coco3811
Contributor I
The code was pasting all in one line.
 
Thanks for taking the time to help a beginner and not getting frustrated until the end..


Message Edited by coco3811 on 2008-06-10 04:05 PM

Message Edited by coco3811 on 2008-06-10 04:06 PM
0 项奖励

1,316 次查看
JimDon
Senior Contributor III
It not a matter of frustration, it's a matter of if you don't do as I say, then things will not work.

I carefully tried it all here, so that it would work, but then if you do not do it the same way there is no chance of it working.

We learn by pain sometimes. That is how we here all learned it. If you want to be an engineer, you have to endure the struggle. I have spent hours over some silly thing. In this case it did not work because of the order of includes it never saw the prototypes for the functions, because the firs file turned on ifdefs for other includes.

You need to be willing th check, double check and then check again. It's all in the details. I know you are learning, and I am tried to help you, and sometimes the student needs a bit of nagging.

If you cut and paste just what is in the box into notepad it should be fine. It also pasted into CW fine as well (yes, I even tried that too).

You will notice nobody else responded - perhaps they are wiser than me.





0 项奖励

1,315 次查看
net11
Contributor III

Hey Jim,

 

I struggled with this same problem for quite some time until I hit the right keywords in the search box to discover this thread. 

I am so glad I did. And just reading it and following all the steps that you mentioned solved it in no time. I am working with the 

MCF5234 board but the steps to the solution are the same. 

It's great that you helped someone with this with a complete correct code posted here. 

Also, due to this person's mistake about the order of the includes, I got to learn not to make that mistake too. 

Keep up the good work! 

 

0 项奖励

1,316 次查看
J2MEJediMaster
Specialist I
No, Jim, it's that we were in awe of your usual good trouble-shooting techniques. Seriously. Well done.

---Tom

0 项奖励

1,316 次查看
JimDon
Senior Contributor III

Well, if that is true, then it is only because I made every mistake possible and spent hours trying to figure it out.
I can't tell you how many time I've hollered because perfectly good serial port code wouldn't work, only to remember I had forgot the set the jumpers (again!).

Thanks for the encouragement.





Message Edited by JimDon on 2008-06-11 04:07 PM
0 项奖励

1,316 次查看
coco3811
Contributor I
Could you include some sample code? I am still stuck :smileyindifferent: thanks.
0 项奖励

1,316 次查看
JimDon
Senior Contributor III
Generate a project for your evb with full board support.
Use the RAM targer.
In  uart_support.c find these functions:


char uart_getchar (int channel)
void uart_putchar (int channel, char ch)

In M52223EVB_sysinit.h you will find:


#if ENABLE_UART_SUPPORT==1

#define TERMINAL_PORT       0
#define TERMINAL_BAUD       kBaud19200

#endif  /* ENABLE_UART_SUPPORT==1 */

#define SYSTEM_CLOCK_KHZ  80000     /* system bus frequency in kHz */


Call these functions with TERMINAL_PORT as in:

Code:
c = uart_getchar (TERMINAL_PORT);      // Read a character.    uart_putchar (TERMINAL_PORT, c);  // echo it.

Something like this should wortk

 
Code:
/* * main implementation: use this sample to create your own application * */#include "support_common.h" /* include peripheral declarations and more */#include "M52223EVB_sysinit.h" // This may be different for you chip.
#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT) /* Standard IO is only possible if Console or UART support is enabled. */#include <stdio.h>#endifint main(void){ int counter = 0; int c; c = uart_getchar (TERMINAL_PORT);      // Read a character.        uart_putchar (TERMINAL_PORT, c);       // echo it.#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT)  printf("Hello World in C from MCF52223 derivative on M52223EVB board\n\r"); fflush(stdout);#endif for(;;) {         counter++; }}

 


0 项奖励

1,316 次查看
coco3811
Contributor I
How do I define TERMINAL _PORT? When I try using just an int i then get an error for the methods getChar and putChar saying that they are undefined. I have tried adding the include statements:
Code:
#include "uart_support.h"#include "uart_support.c"

 
However, I still get an error.
0 项奖励

1,316 次查看
coco3811
Contributor I
Code:
/* * main implementation: use this sample to create your own application * */#include "support_common.h" /* include peripheral declarations and more */#include "MCF52235_sysinit.h"#include "uart_support.h"#include "uart_support.c"#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT) /* Standard IO is only possible if Console or UART support is enabled. */#include <stdio.h>#endifint main(void){// uart_init (0,60000,9600);  int channel = 0; int c = 0;  c = uart_getchar (channel);      // Read a character. uart_putchar (channel, c);       // Echo it./*#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT)  printf("Hello World in C++ from MCF52235 derivative on MCF52235 board\n\r"); fflush(stdout);#endif for(;;) {  }*/ }

 
I am still getting an error saying the methods are undefined. Help please. Do I need uart_init? If I include that I get a bunch more errors..
0 项奖励

1,316 次查看
JimDon
Senior Contributor III
If you create a project with CW 7.0 it's "framework" has all the uart code to do that included.


0 项奖励