Discussion in "Project Help" started by    mem    Sep 25, 2008.
Sat Sep 27 2008, 12:56 PM
#11
hi mem(ory),

first things first, your serial port init is wrong, you are using 9600 baud values for 11.0592 xtal and the TH1 and TL1 values are swapped.




pl.change them to 4800 baud for 24 Mhz xtal ( as given in my last post)


in comm program you have to select flow control as : None






try these changes and get back


Arun
 memnischay kumar like this.
Tue Sep 30 2008, 12:51 PM
#12
I double and triple checked my circuit (diagram and actual) but everything matches up to the tutorial.

I have simplified the code further, looking at the serial_read I see it will wait until it receives a value before returning (correct ?) so the should be no need to check for null characters.

#include <REGX51.H>

void serial_init()
{
        TMOD = 0x20;
        SCON = 0x50;
        TH1  = 0x00;
        TL1  = 0xF3;
        TR1  = 1;
}
void serial_send(unsigned char dat)
{
        while(!TI);
        TI = 0;
        SBUF = dat;
}
unsigned char serial_read()
{
        while(!RI);
        RI = 0;
        return SBUF;
}

void main( void )
{
	signed char c = 0x00;
	serial_init();
	while(1)
	{
		serial_send(0x41);// send A

//		c = serial_read();
//		P0 = c;		
	}
}


Unfortunately neither serial_read or serial_send seem to work (comment out one to test the other).

Putty Settings:

Flow control disabled as recommended.

If I turn the project off and on it will sometimes send rubbish back to putty.

I am currently opening putty then turning the project on, though I do try the reverse when trying all new suggestions, should this matter ?.

So I am stuck again, looking forward to any insight people can offer.


[ Edited Tue Sep 30 2008, 12:53 PM ]
Tue Sep 30 2008, 06:20 PM
#13

Hello mem,

i think you are repeating the same mistake again, please refer to my last post about swapped values of TH1 and TL1. this time you have corrected the timer values for 4800 baud using 24 Mhz xtal but look where are you loading the values ?

since the timer 1 is in 8 bit mode 2 (auto reload) the TH1 needs to be loaded with 0F3h and TL1 with 00h, but check what you are doing !



Arun
 mem like this.
Tue Sep 30 2008, 11:28 PM
#14
Arun, sorry I missed that last part about having my values swapped, I missed that section when rereading this thread last night. Thank you for your patience. I shall try again tonight after I have corrected my mistakes.
Wed Oct 01 2008, 12:43 PM
#15
Thanks Arun, indeed it was as simple as setting the correct values for the registers like you said.

The completed code:
#include <REGX51.H>

void serial_init()
{
        TMOD = 0x20;
        SCON = 0x50;
        TL1  = 0x00;
        TH1  = 0xF3;
        TR1  = 1;
}
void serial_send(unsigned char dat)
{
        while(!TI);
        TI = 0;
        SBUF = dat;
}
unsigned char serial_read()
{
        while(!RI);
        RI = 0;
        return SBUF;
}
void main( void )
{
	signed char c = 0x00;
	signed char c_old = 0xFF;

	serial_init();

	while(1)
	{
		c = serial_read();
		P0 = c;
		serial_send(c);
	}
}


For sending data, flow control can be either XON/XOFF or none (rest untested, but it does not seem to matter).
For receiving however flow control NONE does not work, it returns a short bit of random characters then the chip locks up (as far as I can tell). Using XON/XOFF flow control does work perfectly though, all characters pressed are echoed back to the putty terminal. A guy I work with (who used todo alot of high level electronics) said the way the diagram is wired in mine and the tutorial it is ment for XON/XOFF, I have forgotten his explanation but I will post tomorrow when I see him.

Correct putty settings:


Now a few quick follow up questions
1) Only indirectly releated to electronics, but can anyone suggest a plugin for winamp/xmms/amarok that will allow me to send data to the comport (I dont mind having to adjust code).
2) Does someone have a chart or a formula for calculating correct crystal values for a given baud rate (will be really handy for the howto I will write up).

Thanks again everyone
Wed Oct 01 2008, 04:20 PM
#16

Hi mem,

so finally your project worked as expected, congrats ! !dance



Arun
 mem like this.
Wed Oct 01 2008, 08:36 PM
#17
mem you could face problem, just thinking about default values.
i mean when u power up your controller, TI is 0 by default. so when sending data on UART, you will get stuck in while loop of transmit function.
here i mean
while(!TI);


so best thing is, set this bit to 1 during initializing uart.
and great job keep practicing..
 mem like this.
Wed Oct 01 2008, 11:47 PM
#18
Ajay,
I believe thats the intended behavior of those sub routines (from the tutorial), ie HALT until data is received (RI) and wait till port is ready for a transmission (TI) and then send.
So (and please correct me if Im wrong) but wouldnt setting TI to 1 have no effect as the chip will reset it ?
Thu Oct 02 2008, 09:27 PM
#19
no there is no effect on setting TI bit as you are doing it at the starting of your program, when everything is getting initialized. and its just for safety. The TX part of 8051 uart never starts working unless you move data to SBUF register or say TX works only after this instruction
mov SBUF, A ;or any register

or in C
SBUF = data_to_send;


so by setting TI bit you mean assuming that TX part is ready to send next data.
This practice is used in many other microcontrollers too. so its good to add that TI = 1; instruction in your code.
 mem like this.
Fri Oct 03 2008, 03:06 AM
#20
Cool mate, thanks for explaining that to me

I have been working on the PC side of my project atm, I have gutted an xmms (linux clone of winamp) plugin and got it to output the data in text I want in sync with the music, today Im going to try out an example serial port c program I found here: com.c

Once I have modified that program todo as I want I will join it to my xmms plugin and tada, a very basic VU meter .

I also found some good information on calculating the timings in a 8052.com tutorial

Looks fairly detailed, so when I have a chance (been very busy of late) I will read through that and include the relevant info in the howto.

Get Social

Information

Powered by e107 Forum System

Conversation

ExperimenterUK
Sat Mar 25 2017, 09:56 PM
@Noreen I suggest you log in and post a full description of what you need in our PIC forum
Sat Mar 25 2017, 03:10 PM
Noreen
Hello I worked on a project related to Wireless Electricity theft detection using GSM during my bachelors. I used Nokia 6230 for sending sms using AT commands. I chose to work with SMS text mode. The microcontroller I used was PIC16F877A and its software coding done through PIC Basic Pro. Unfortunately, I lost my account password and do not have coding for generation sms using AT commands. I need that coding. Can some one help me to provide complete Pic Basic Pro code. In which step by step guidance is given so that I can understand easily. Regards,
Wed Mar 22 2017, 09:13 PM
ajay kumar
help me nokia lcd light
Wed Feb 22 2017, 06:14 AM
ChollyMo
Indeed, on the LCD tutorial, many missing Tables and figures !!
Wed Feb 22 2017, 06:06 AM
ChollyMo
I don't see any Table 3. I'm using Chrome.
Fri Feb 03 2017, 05:56 AM
irfan shaikh
hi, i want interface WS2811 pixel led using NUVOTON N79E352, but i dont know how to code it. can anyone help me or provide me sample coding for interfacing WS2811 PIXEL LED. THNX
Thu Jan 19 2017, 08:42 PM
abhays
Hi...i have made a circuit for interfacing PT100 with LM358 whose temperature is shown on the LCD...But the temperature is not getting incresed slowly ..a small change directly increses the temp...can any one help me
Thu Jan 19 2017, 04:27 PM
roba
send me alarm clock simulation using proteus software
Mon Jan 16 2017, 03:15 PM
Rutuja
How can we read notepad file using random acess file
Fri Jan 06 2017, 06:18 AM
muhammad Umar
i need cd4047 library file for protious please help me i s

Downloads

Comments

SAUnwin
Tue Mar 21 2017, 02:29 PM
letonarolikah
Mon Mar 20 2017, 11:21 AM
nerodear
Tue Mar 14 2017, 07:08 AM
XuZiling
Wed Feb 22 2017, 02:40 AM
diwakar_96
Thu Feb 16 2017, 02:40 PM
Helia
Thu Feb 09 2017, 09:59 AM
fasihaftab
Sat Jan 28 2017, 08:58 AM
jmunjr
Tue Jan 17 2017, 06:25 PM

Online

Guests: 60, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37804
Newest member: SAUnwin
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Mar 25 2017, 09:49 PM
I have attached code showing one method you could ...
Deepakvaishu Avatar
Posted By Deepakvaishu
Sat Mar 25 2017, 07:59 AM
I am using Keil and 8051 microcontroller
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Mar 24 2017, 06:05 PM
The best way is to use an interrupt to run the cou...
Deepakvaishu Avatar
Posted By Deepakvaishu
Fri Mar 24 2017, 05:22 AM
Hi,I got that we should use timer......But I am a ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Mar 23 2017, 09:14 PM
You have largely answered your own question.Use on...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Mar 23 2017, 07:03 AM
I have looked at your code.I think you are confuse...
Deepakvaishu Avatar
Posted By Deepakvaishu
Thu Mar 23 2017, 05:34 AM
hello,I can type the letters now when the particul...
SAUnwin Avatar
Posted By SAUnwin
Tue Mar 21 2017, 02:55 PM
HI,There are two ways I'd tackle thiss.Key down on...
Deepakvaishu Avatar
Posted By Deepakvaishu
Mon Mar 20 2017, 08:24 AM
hello,I am using a keypad to type the text message...
Helia Avatar
Posted By Helia
Thu Mar 16 2017, 09:15 AM
hi.. the following code is not working on hardware...