Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help needed in serial commucnication

Status
Not open for further replies.

pakhi

New Member
hello,

i'm writing modbus code for function 15 in keil using C.In this maximum no. of bytes to be received is 264 & it can be vary from minimum 10 bytes to maximum 264 bytes from user side.

here i have taken one array whose dimension i had taken 264 & each time whn i'm receiving the byte i'm comparing it to either 264 (or null character).after satisfying this condition other part of the program gets executed.this is working fine while debugging the code on keil.

but the probl is that whn i'm executing this code on hardware,then it seems tht microcontroller(AT89C2051) is receiving the data but it is not trnsmiting any thg at all.... The code for this is gvn below

void main()
{
TMOD = 0x20;
SCON = 0x50;
P1 = 0xFF;
DE = 0;
TH1 = 0xFD;
TL1 = 0xFD;
EA = 1;
ES = 1;
TR1 = 1;
while(1)
{
query(); //to receive the character frm user
if(count=='\0')
f = 1;
}
}

void query(void)
{
while(recv_flag)
{
recv_flag = 0;
if(count!='\0')
Recv_Buff[count] = recv;
count++;
}
}

void serial(void) interrupt 4
{
if(RI==1) //if RI interrupt is set to 1
{
RI=0;
DE = 0;
recv=0;
recv = SBUF;
recv_flag=1;
}
else
{
TI = 0; //if TI interrupt is set to 1
DE = 0;
nt++;
if(nt==8)
{
nt = 0;
f = 0;
crcok = 0;
m = 1;
}
if(excep==1)
{
ct++;
if(ct==5)
{
h = 1;
ct = 0;
excep = 0;
f = 0;
m = 1;
}
}
}
}



So,where is the problem i can't able to make out can anyone plz help me out for this..... Although this code is working fine when i have to send the fix no. of bytes.

thanx,
 
Modbus No. of bytes

I recall that somewhere in the MODBUS specs there was a limit of bytes including two for CRC at the end. Not sure if it was less than 255. :?:

Could you please check that? If it has nothing to do with you problem, excuse me :!: :!:

I don't know C. Sorry
 
Your code is incomplete. You left out the variable declarations. It could be the variable for byte count is declared as BYTE. Lastly could you please format your post using the "code" BBCode? I'd like to help but you don't make it easy.
 
help needed for serial communication

hello,

i got the solution....

thanx for ur response
bye
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top