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

Mon Jun 12 2017, 07:36 PM
madhusoodanan
how to receive string using 8051
ajay_bhargav
Thu Jun 08 2017, 05:48 PM
@Vinoth post in forum.
Wed Jun 07 2017, 06:40 AM
vinothkannan
how interface eprom in this code
Thu May 25 2017, 05:25 AM
Monir Hossain
Can i change the 7-Segment are common pin ? And how to?
Mon May 08 2017, 12:45 PM
ivan muvunyi
please can you send me wiring diagram for automatic control of 3 phase induction motor for production of maize flour
Wed May 03 2017, 08:39 PM
imran qureshi
hello friend
Sun Apr 30 2017, 05:49 AM
Lijin G Varghese
Can u send me the circuit diagram for Program to interface GSM Module with 8051 microcontroller (AT89C51) using PC and LCD
Fri Apr 28 2017, 03:47 PM
SANDEEP T S
I need pcb wizard 3.5 version kindly send valid link of yours
ExperimenterUK
Mon Apr 17 2017, 11:56 PM
Sorry..We had a problem with registration.Confirmation emails were not sent.Please re-register
Thu Apr 13 2017, 07:29 PM
Piyush Aughad
I want circuit & program for radar detection using Microcontroller 8051

Downloads

Comments

richard1976
Sat Jun 24 2017, 05:48 PM
DruvaN
Wed Jun 21 2017, 11:44 AM
lalala
Tue Jun 20 2017, 11:05 PM
Siddh@
Tue Jun 20 2017, 07:47 AM
firdaus0hsem
Sat Jun 17 2017, 04:53 PM
amir9297
Fri Jun 16 2017, 05:44 AM
madhusoodhanan
Mon Jun 12 2017, 07:31 PM
Aminookano
Sun Jun 11 2017, 05:50 AM

Online

Guests: 59, Members: 0 ...

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

Members: 37847
Newest member: richard1976
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Jun 26 2017, 08:42 PM
I have attached a demonstration file.It will echo ...
richard1976 Avatar
Posted By richard1976
Sat Jun 24 2017, 08:47 PM
Hi can you tell me how to send and recieve usart d...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Jun 24 2017, 08:24 PM
HiUnfortunately there is too much code here to wor...
richard1976 Avatar
Posted By richard1976
Sat Jun 24 2017, 06:01 PM
hi i have written this programme and can send data...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jun 23 2017, 08:19 PM
>Should I need to check PWR_VLD bits every time on...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jun 23 2017, 07:42 PM
I would say yes, but data transfer will be slower ...
Utsavi Avatar
Posted By Utsavi
Thu Jun 22 2017, 12:14 PM
Hello ExperimenterUK, Thanks for your support. Fro...
DruvaN Avatar
Posted By DruvaN
Wed Jun 21 2017, 11:51 AM
Is it possible to Use 8051 bit-banging method to p...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jun 20 2017, 06:27 PM
You could start by looking at this tutorial on ke...
firdaus0hsem Avatar
Posted By firdaus0hsem
Sat Jun 17 2017, 04:58 PM
I have an issue regarding how to use 4x3 keypad to...