Help in serial RS-232 commenecation

Hi .

I have RCM4100 Development Kit. with Rabbit 4000.
I used the following code to send letters from ( a to z ) to the serial PC com1. using port D . but the result was as following :
" abcdefghijk " Only , So Please if any one can help me and indicate where is the error.

the Code is :

#class auto

#define DINBUFSIZE  15
#define DOUTBUFSIZE 15

#ifndef _232BAUD
#define _232BAUD 115200
#endif

#define RS232_NOCHARASSYINBRK

main()
{

	auto char cOut;

	serDopen(_232BAUD);
  	serDwrFlush();
	serDrdFlush();


		for (cOut='a';cOut<='z';++cOut)
		{
			serDputc (cOut);
	}
}

also i see that I received a continuous message " abcdefghijk " even I didn’t using any infinity loop for that.

regards

Your program is returning from main and ending before the serial buffer has been completely sent. If you add

printf("Press any key to exit.");
while (!kbhit());

after the for loop, you will see the whole string is sent. If you unplug the programing cable with your original program (or have it attached to the DIAG connector) you will see the truncated string repeat as the watchdog timer is reseting the processor and running your program again and again, each time producing the same truncated string. This is where the “mystery loop” is coming from.

Dear bsprouse

Thanks for you help

I do what you advised me , and the program works correctlly.
But when I changed the bude rate to 9600. I recived only the following : “abcdefghijklmnop” only.:confused::confused:

So Please could you inform me why.:stuck_out_tongue:

Regards
Redwan

You have your buffer set to 15 characters. At 9600 baud it takes much longer to send each character. On the other hand, the loop you use to send the string happens in mere microseconds. When you overrun the buffer, the additional characters are getting lost. Change your buffer defines to:

#define DINBUFSIZE 31
#define DOUTBUFSIZE 31

This will fix your sample, but in the real world, at 9600 baud, you may need to make your outgoing buffer substantially larger based on the size of the strings or packets you intend to transmit.

as you posted i have tried the same with the altration with the help of Bill Sprouse on my RCM4000. actually wat i am doin here is, i have a xbee module on my system which act as a transmitter and ther is a xbee receiver on a PIC16f877a. using this code i am transitting the data a to z. but on hyperterminal on PIC side, it dosent displaying any even a single charactr which i ve transmitted. its printing some other char and that hyperterminal page goes to black and still on. when i make new connection i could get a clear screan. whats going on? why its so?

here i have posted my code. pls go through this and pls pls pls pls tell me sum solutions…

#class auto

#define DINBUFSIZE 31
#define DOUTBUFSIZE 31

#ifndef _232BAUD
#define _232BAUD 9600
#endif

#define RS232_NOCHARASSYINBRK

main()
{

auto char cOut;

serDopen(_232BAUD);
serDwrFlush();
serDrdFlush();




  for (cOut='a';cOut<='z';++cOut)
	{
  costate
  {
  waitfordone
  {
cof_serDputc (cOut);
  }
  }
  }while(!kbhit());

}

This code looks OK, does it work if you just hook the Serial Port D output to a PC? If so, then my guess would be you don’t have your ZigBee network setup properly. ZigBee networks are not completely automatic. You have to have a configurator and then routers or endpoints have to be added to the network. Once this is done, they are fairly automatic. Are you sure your ZigBee network is operational?

“does it work if you just hook the Serial Port D output to a PC? If so, then my guess would be you don’t have your ZigBee network setup properly. ZigBee networks are not completely automatic. You have to have a configurator and then routers or endpoints have to be added to the network. Once this is done, they are fairly automatic. Are you sure your ZigBee network is operational?”

from your reply i ve tried for the serial port too. i am getting the same result.

first i want clear one thing that is i had worked with the same xbee module with two PIC16f877a boards which act as a transmitter board and another is a receiver board. i had a TXR board with my PC and RXR board placed with another PC. here actually we had connected xbee through UART. could you assume what we had done?

pls ask me if you not clear on my points. pls pls pls…

so is there any need of xbee network configuration? we were using 9600 baudrate in our code and hyperterminal. its was working fine. whatever i type on keyboard it was printing nice.

from this i have removed one xbee transmitter and connected with my RCM4000 using UART. i had ru the same code which i posted in my previous post. i am getting the result which is not readable. pls help me out…

OK, if you’ve had the ZigBee units running in serial link mode, then we’ll assume they are not the problem. My next question is how do you have the ZigBee module connected. Is it tied directly to PC0 and PC1 or are you going through the RXD/TXD connections on the dev board? Are you using a dev board? If so, and you have the Xbee connected to PC0 and PC1, are you aware that you need to remove the 0 ohm resistor marked JP5 to isolate the receive line (PC1) from the transceiver chip on the dev board. Otherwise you have the transceiver chip driving the same line the Xbee module is trying to transmit on. Look at the schematic for the dev board and you can see JP5 connects the receive side of the transceiver onto PC1. The schematic for the dev board can be downloaded here:

[http://www.rabbit.com/documentation/schemat/090-0230.pdf](http://www.rabbit.com/documentation/schemat/090-0230.pdf)

Hi,
Its working when i connect my RX and TX pin of xbee to PC2, PC3 directly but when i transmit a single char its working nicely. but when i send the string continuesly, some datas not special chars but some chars which is not sent by me is printing. why???

thanks for all your reply…

here’s my code

#class auto

#define CINBUFSIZE 31 //buffer size of input data
#define COUTBUFSIZE 31 //buffer size of output data

#ifndef _232BAUD
#define _232BAUD 9600 //set the Baudrate
#endif

#define RS232_NOCHARASSYINBRK

main()
{

auto char cOut,i;

serCopen(_232BAUD);
serCwrFlush();
serCrdFlush();

  do
  {
  for (cOut='a';cOut<='z';++cOut)
	{
  //for(i=0;i<9000;i++);
  costate
  {
  waitfordone
  {
cof_serCputc (cOut);           //Writing the data to 
  }                                           //serial pot
  }
  }
  }while(!kbhit());                 //Checking whether any key is pressed or 
  printf("key pressed");          //not

}