Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 28th June 2008, 03:14 PM   #1
Default BoostC USART 18F

Ok im having some trouble receiving from Hyper Terminal to my PIC18F1320.
Im using BoostC to program/

I can send data out with no problem... Here is my receive code:
Code:
void RxRecv(char &MyTmp)
{
    while(!pir1.RCIF);

        MyTmp = rcreg;
        Rs_Send(rcreg);
}
and this is how im calling it
Code:
    while(1)
    {
        char Tmp2 = 0x00;
        RxRecv(Tmp2);
    }
Now for some reason when i type a key in hyper terminal it wont work. But i have the same code in ASM and it works fine on same chip. Any thoughts?

Last edited by AtomSoft; 28th June 2008 at 03:17 PM.
AtomSoft is offline  
Old 28th June 2008, 03:43 PM   #2
Arrow

The argument of the function RxRecv() looks wrong to me.
Does this work?

Code:
unsigned char MyTmp;

unsigned char RxRecv(){

    while(!PIR1.RCIF);
    return RCREG;

}

// ....

while(1){

    MyTmp = RxRecv();
    Rs_Send(MyTmp);

}

Last edited by eng1; 28th June 2008 at 03:43 PM.
eng1 is offline  
Old 28th June 2008, 04:04 PM   #3
Default

Quote:
Originally Posted by AtomSoft View Post
I can send data out with no problem... Here is my receive code:
Code:
void RxRecv(char &MyTmp)
{
    while(!pir1.RCIF);

        MyTmp = rcreg;
        Rs_Send(rcreg);
}
Try changing it to void RxRecv(char *MyTmp) and your calling code to RxRecv(&Tmp2);

The (char *) tells the compiler to expect a pointer with the address of a char variable and &Tmp2 passes the address of the variable.

Mike.

Last edited by Pommie; 28th June 2008 at 04:14 PM. Reason: clarification.
Pommie is online now  
Old 28th June 2008, 06:11 PM   #4
Default

The actual issue is i cant seem to get passed the (bold):
Code:
void RxRecv(char *MyTmp)
{
    while(!pir1.RCIF);  //Not correctly checking Flag even with 
                        //a breakpoint i cant skip this

        *MyTmp = rcreg;
        Rs_Send(rcreg);
}
AtomSoft is offline  
Old 28th June 2008, 06:44 PM   #5
Default

Did you set bit CREN, that enables the reception?
eng1 is offline  
Old 28th June 2008, 06:52 PM   #6
Default

yes here is my full code: (still nothing)
Code:
#include <p1320.h>
#pragma	CLOCK_FREQ 8000000

void Rs_Init()
{
    //RS Init.
    trisb = 0b00010010;
    portb = 0x00;
    spbrg = 0x0C;
    txsta.BRGH = 0;
    baudctl.BRG16 = 0;
    txsta.SYNC = 0;
    rcsta.SPEN = 1;
    rcsta.CREN = 1;
    txsta.TXEN = 1;
}

void Rs_Send (char tx_char)
{
    while(!pir1.TXIF);
    txreg = tx_char;
        
}

void puts(char *source)
{
	while (*source != 0) // wait until tx register is empty
	    Rs_Send(*source++);
        Rs_Send(0x0d);
        Rs_Send(0x0a);
}


void RxRecv(char *MyTmp)
{
    while(!pir1.RCIF);  //Not correctly checking Flag even with 
                        //a breakpoint i cant skip this

        *MyTmp = rcreg;
        Rs_Send(rcreg);
}


void main()
{
    //PIC Init.
    osccon.IRCF2 = 1; // 8Mhz Clock
    osccon.IRCF1 = 1;
    osccon.IRCF0 = 1;

    Rs_Init();    

    puts("Hello, world\r\n");
  
    while(1)
    {
        char Tmp2 = 0x00;
        RxRecv(&Tmp2);
    }
}

Last edited by AtomSoft; 28th June 2008 at 06:52 PM.
AtomSoft is offline  
Old 28th June 2008, 07:57 PM   #7
Default

You did not configured the A/D channels, did you? Try adding this line at the begining of the main function:
Code:
ADCON1 = 0xFF;
eng1 is offline  
Old 28th June 2008, 08:43 PM   #8
Default

Does this work?
Code:
char Tmp2 = 0x00;
while (1) {
      if (pir1.RCIF) {
         Tmp2 = rcreg;
         Rs_Send(Tmp2);
      } // end if
} // end while
Why not use an interrupt?

Last edited by BeeBop; 28th June 2008 at 08:45 PM.
BeeBop is offline  
Old 28th June 2008, 09:52 PM   #9
Default

Quote:
Originally Posted by eng1 View Post
You did not configured the A/D channels, did you? Try adding this line at the begining of the main function:
Code:
ADCON1 = 0xFF;
Thanks a bunch! this works now. I should have seen it in my asm code but i guess i was going to fast! thanks a lot.
AtomSoft is offline  
Old 29th June 2008, 05:02 PM   #10
Default

Full Code Everything WORKING ! 100%
Attached Files
File Type: c RS.c (4.7 KB, 29 views)
AtomSoft is offline  
Reply

Tags
18f, boostc, usart

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
BoostC Charlieplexed PWM 32 Mike, K8LH Micro Controllers 140 27th March 2009 11:19 AM
BoostC question.. AddressOf Mike, K8LH Micro Controllers 8 25th June 2008 12:20 AM
LCD degree symbol with sprintf (BoostC) futz Micro Controllers 29 5th June 2008 05:19 AM
math.h and lib for BoostC? futz Micro Controllers 3 31st March 2008 06:29 AM
PIC USART: Help Please mortuzahasan Micro Controllers 2 11th February 2007 07:28 PM



All times are GMT. The time now is 02:46 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker