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

Wed Nov 08 2017, 01:35 PM
Anirudh jain
I want to burn code in atmel 89s51 24pc 0329 but cannot get the connection with the burner. Can somebody provide me with the circuit diagram for connecting controller to burner. I'm using usb burner
Thu Nov 02 2017, 11:44 AM
karpal
write a program to exchange the content of b register with external RAM address 02CFH help me
Wed Nov 01 2017, 05:47 PM
sanae
i am using the DHT11 but i'm getting some errors in the simulate the programe in proteus 8 professional,: 1)cannot find model file 'DHTXX.MDF'.2)simulation failed due to netlist linker error(s).
Fri Sep 29 2017, 02:45 AM
Maaz
i am doing the same project on verilog please contact me [email protected]
Wed Sep 20 2017, 12:36 AM
Ted
In a missing pulse detector using a 555 timer connected as a monostable vibrator with a PNP transistor,how does the positve input pulse turn on the PNP transistor?
Sun Sep 03 2017, 02:29 PM
martymarty
How do I connect an <NOKIA 1100 LCD > to an atmega328P ?
poojab51296
Sun Aug 20 2017, 10:23 AM
i am intending to interface sd card with STM32F4 and want to write a file in sd card using SPI protocol but using HAL only. Can anyone help me PLEASE!!!!
poojab51296
Sun Aug 20 2017, 10:22 AM
hello
rawat742
Fri Aug 18 2017, 11:37 AM
hi @ angel patel i will attach a file i hope it will be helpfull for you
ExperimenterUK
Mon Aug 14 2017, 09:57 PM
@ angel patel... just log in and post your problem

Downloads

Comments

PANDIKOTESWARARAO
Mon Nov 20 2017, 07:40 PM
Hemantika
Sun Nov 19 2017, 07:34 PM
Wed Nov 15 2017, 10:46 AM
Ansh12
Sat Nov 11 2017, 03:43 AM
AngelGT93
Fri Nov 10 2017, 06:53 AM
JardCrocker
Wed Nov 08 2017, 05:27 PM
vivitern
Tue Nov 07 2017, 09:08 AM
catrons
Sat Nov 04 2017, 10:46 PM

Online

Guests: 44, Members: 0 ...

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

Members: 37918
Newest member: PANDIKOTESWARARAO
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Nov 20 2017, 10:18 PM
Here is a version of the tutorial that reads a key...
Ansh12 Avatar
Posted By Ansh12
Mon Nov 20 2017, 02:15 AM
As a starting point, can you tell us how much of t...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Nov 19 2017, 08:35 PM
As a starting point, can you tell us how much of t...
Ansh12 Avatar
Posted By Ansh12
Fri Nov 17 2017, 04:07 AM
I am looking keypad interfacing program. I was rea...
JardCrocker Avatar
Posted By JardCrocker
Wed Nov 08 2017, 05:29 PM
Hi...i am a new user here. I was also facing the s...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 07 2017, 07:13 PM
> It employs a fairly advanced technique to detect...
vivitern Avatar
Posted By vivitern
Tue Nov 07 2017, 09:33 AM
I own a used Clavia ddrum4 SE drum module. It empl...
bvdb Avatar
Posted By bvdb
Wed Oct 18 2017, 01:50 AM
I purchased the RKitL51 8051 C compiler from Raiso...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Oct 16 2017, 11:44 PM
That looks complicated.Is 8051_BLK a standard 80...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Oct 15 2017, 07:29 PM
According to this, gmail should support POP3.https...