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 on code implementation=)

Status
Not open for further replies.
That wont even compile. Can you post code that at least compiles. The first line that gives an error is the line I asked about 1 month ago.
Code:

unsigned char data[3]="A","T","R"; //store bytes in array because bytes are to be sent one by one.

Mike.

i am sorry i forgot to change my code before i posted. I used the 2nd method u told me a month ago which is
unsigned char data[4]="ATR";

i am really so sorry
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
i did tests on the osc just a few mins back and i found out that i dont need to even define the ASCII characters as my compiler wil just send out the hex value straight out the Tx Pin.

#define A 0x41 //assign ASCII byte code to A
#define T 0x54 //assign ASCII byte code to T
#define R 0x0d //assign ASCII byte code for Carriage Return
all not needed


if thats the case, how should i send out the CR command?

thanks Mike
 
hey i can now send out CR ..i just did the following

unsigned char data[3]={'A','T','CR'};

(i reverted to the first method you told me a month ago)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


how should i implement my receving of OK?

thanks=)
 
You can put 0x0d in the string by doing,
Code:
unsigned char data[4]="AT\x0d"; //store bytes in array because bytes are to be sent one by one.
Note, it is 4 characters long because when you use double quotes it adds a zero to the end.

However, it is normal that you send Cr Lf and so you should do,
Code:
unsigned char data[5]="AT\x0d\0x0a"; //store bytes in array because bytes are to be sent one by one.

You should then change your code to look for the zero,
Code:
for(count=0;data[count]!=0;count++){
    while(!TXIF);
    TXREG=data[count];
}

//or

count=0;
while(data[count]!=0){
    while(!TXIF);
    TXREG=data[count++];
}
Note that there is no need for a delay now as you are not trying to see it on a scope.

Mike.
 
There was an error message generated at this line:
unsigned char data[5]="AT\0x0d\0x0a";

with the error message:
Error [240] C:\MPLAB\serial comm\serial development.c; 51. too many initializers

what does it mean?

thanks
 
It means you can't copy correctly, it should be,
Code:
unsigned char data[5]="AT\x0d\x0a";
Not,
Code:
unsigned char data[5]="AT\[COLOR="red"]0[/COLOR]x0d\[COLOR="Red"]0[/COLOR]x0a";

Mike.
 
hey mike

with this code,

unsigned char data[5]="AT\x0d\x0a";

for(count=0;data[count]!=0;count++){
while(!TXIF);
TXREG=data[count];
}

there was no output seen on the scope.

when i changed the 'sending out part' to my old code,there was output with the 4 bytes coming out on the scope.

for (count=0;count<4;count++)
{
while(!TXIF);
TXREG=data[count];

could it be that the first value in the array{'A'} is indexed at 0, that is why it wont be sent out if data[count]!=0???


the bytes on the scope came out as expected..however when i connected it to hyper terminal, 4 bytes came out but are not AT <carriage return><line feed> but some jumbled up characters..im guessing that its a problem with my max232 converter cuz the pk to pk rs232 waveform converted by the max232 is only about 4Volts...
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

when i send out an AT to the hp, im expecting to receive an OK from the hp..how do i implement the reception of this byte?

thanks alot for ur help=)
 
That code works fine. You probably didn't see anything on the scope because it was too fast with the delays removed. However, you can't keep the delays as the phone will reply during the delay.

Before going any further you should get it working with hyperterminal. Check you have the right baud rate, start/stop bits, parity etc. I assume it should be 9600,n,8,1.

If that is correct then double check your wiring of the MAX232. See attached.
Edit, a 5V power supply also needs connecting to the MAX232.

Mike.
 

Attachments

  • MAX232.png
    MAX232.png
    11.5 KB · Views: 254
Last edited:
However, you can't keep the delays as the phone will reply during the delay.
i will remember that thanks..
Before going any further you should get it working with hyperterminal. Check you have the right baud rate, start/stop bits, parity etc. I assume it should be 9600,n,8,1.
yup the settings are all correct


based on ur given max232 diagram, it appears that caps C5 and C6 on your diagram are connected in reverse polarity to what is stated in the datasheet. is the datasheet connection wrong? i tried both connections but my pk-pk value is still 4V+..i even replaced my old max232 with a new one i bought just now...still 4V pk-pk

http://www.datasheetcatalog.org/datasheet/maxim/MAX220-MAX249.pdf
 
The caps aren't polarized, they are 1uF ceramics. If you are still seeing only 4V then I would suspect your power supply isn't up to the job.

Mike.
 
i have identified the problem (my breadboard connection oversight did not power up the max232) thank you so much for your help=)

i can now send the command AT <CR><LF> to hyperterminal..

how should I implement the reception of OK??

when pic is connected to hyperterminal, i noticed that at the instant when i first power up the pic, the first 2 bytes are corrupted...should i add a delay at the beginning to avoid this?


thanks=)
 
would this be correct?

ATOK(); //command to send out AT to handphone


unsigned char indata[2]; //start of receiving "OK" code
while(!RCIF);
for(count=0;count<2;count++)
{
while(!RXIF)
indata[]=RCREG;
}

for (count=0;count<2;count++)
if (indata[0]="O" && indata[1]="K")
{
TRISB=0x00;
PORTB=0xFF;
}
 
i am trying to keep sending out AT until i receive an OK verification in which Port B will go HIGH to light up an LED...i wrote the code as follows but it doesnt work..

is my sending out of "AT" for this case correct? because now i am not able to detect any output from Tx...

////////////////////////////////////////////////////////////////////////////////////////

void ATOK(void)
{
unsigned char data[4]= "AT\x0d"; //store bytes in array because bytes are to be sent one by one.


unsigned char out;

for (count=0;count<4;count++)
{
while(!TXIF);
TXREG=data[count];
}
}


////////////////////////////////////////////////////////////////////////////////////////

void main()
{
serial_setup(); //Set up transmit and receive registers

__delay_ms(500);
__delay_ms(500);

ATOK(); //command to send out AT to handphone
unsigned char indata[1]; //start of receiving "OK" code
while(!RCIF);
for(count=0;count<2;count++)
{
while(!RXIF);
indata[]=RCREG;
}


if (indata[0]="O")
{
TRISB=0x00;
PORTB=0xFF;

}
else
{ATOK();
}


}
 
Nearly but with a couple of errors,

Code:
unsigned char indata[2]; //start of receiving "OK" code
for(count=0;count<2;count++)
{
    while(!RXIF);		//must have semi colon
    indata[count]=RCREG;
}

if (indata[0]=='O' && indata[1]=='K')  //single quotes and double equals 
{
    TRISB=0x00;
    PORTB=0xFF;
}

Mike.
 
Last edited:
when i program AT to be sent for only 1 time, the AT string does not appear on hyper terminal..

it only appears on hyperterminal when i send it in an infinite loop...how should i send out AT for just one time...

is my code to send out AT (2posts back) correct?


if (indata[0]='O' && indata[1]='K') //single quotes
{
TRISB=0x00;
PORTB=0xFF;
}


i tried this code with single codes but it could not compile and an error generated.

#windows popup #
cgpic.exe has encountered a problem and needs to close. We are sorry for the inconvenience.

it could only compile with double quotes...would double quotes be wrong?

thanks..
 
I missed a mistake, see my edit above. Also, it is RCIF not RXIF.

For the error when powering up try changing the order in your setup so SREN=1 is the last thing you do.

Mike.
 
i tried to continually send AT to the hp until i received the "O" from the hp indicating the OK string....however there seems to be no output at all on the Tx pin of the PIC...the code is able to compile..but i guess im implementing it wrongly.wad is wrong?

while (indata[0]!='O')
{
ATOK();
for(count=0;count<2;count++)
{
while(!RXIF);
indata[count]=RCREG;
}
}


TRISB=0x00;
PORTB=0xFF;
}
 
i did tests to see whether an OK would return from the HP on hyperterminal but no OK was received although a confirmed AT was sent to it...

im wondering...should pins 7 and 8 (CTS and RTS) of the serial port for the handphone or is it okay to leave it unconnected? im using the SE T630..does it require an indication that it is clear to send??


thanks
 
It's your device, you'd have to find the specs for it to be sure.
 
Status
Not open for further replies.

Latest threads

Back
Top