Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Read to an array from serial port and a can baud rate calculation

Status
Not open for further replies.

Magvitron

Full Member level 5
Full Member level 5
Joined
Aug 8, 2012
Messages
241
Helped
25
Reputation
142
Reaction score
71
Trophy points
1,328
Location
Kollam (Quilon), India, India
Visit site
Activity points
2,331
Hi, I am building a CAN n/w using pic 18f25k80. Can any one help in the following
1. Calculating the baud rate of CAN
my current setting
Code:
//Setup the Baud Rate @16 Mhz.
    BRGCON1 = 0xc3;
    BRGCON2 = 0x9e;
    BRGCON3 = 0x03;
2. How to read from the UART to an array
my current code (this is not working) ie there is no update in array.
Code:
/**************************
Initialize the serial port
@ 160000 and 230400bps
***************************
Requires :none
Returns : none
**************************/
void uart_init()
{//Enables Serial port  
/*RCSTA RECIEVER CONTROL REGISTER*/  
RCSTA1bits.SPEN = 1;
RCSTA1bits.RX9=0;//8 bit reception
RCSTA1bits.CREN = 1; //enable the reciever

  TRISCbits.TRISC7=0;
  TRISCbits.TRISC6=0;
/*TXSTAx: TRANSMIT STATUS AND CONTROL REGISTER */
TXSTA1bits.BRGH=1;//baud rate high bits    
TXSTA1bits.SYNC=0;//assynchronous mode      
TXSTA1bits.TX9=0; //8 bit reception
TXSTA1bits.TRMT=1;//reset the buffer
TXSTA1bits.CSRC=0;// Master mode  (clock generated internally from BRG)
/*BAUDCONx: BAUD RATE CONTROL REGISTER*/
BAUDCON1bits.BRG16=1;//16 bit Baud rate is enabled

SPBRGH1 = 0;
SPBRG1 = 16;//2;
//(((_XTAL_FREQ/baud)/4)-1);
//FCY/64)/BAUD) - 1;
// set baud to 9600  FCY=20000000
//Turn On the Tx and Rx
TXSTA1bits.TXEN=1;
RCSTA1bits.CREN=1;
}
///////////////////////////
//Function for read to a buffer
///////////////////////////
//Requires  : <Xc.h>,Uartinit
//Returns  : None
//Parameters: None
///////////////////////////
void uart_read2buff()
{
int count;
while(uart_read()>0)
{
  rxr[count]=uart_read();
  uart_char(uart_read());
  count=count+1;
  uart_num(count);
  if (count>63)
  break;
 
}
uart_string("out of here");
rxr[count]='\0';
count=0;
}
//////////////////////////
//Function for sending char
///////////////////////////
//Requires  : <Xc.h>,Uartinit
//Returns  : None
//Parameters: None
///////////////////////////
void uart_char(char data)
{
TXREG1= data;
  while(!TXSTA1bits.TRMT);
}
///////////////////////////
//Function for reciveing from serial
///////////////////////////
//Requires  : <Xc.h>,Uartinit
//Returns  : None
//Parameters: None
///////////////////////////
char uart_read()
{
while(!RC1IF);
RC1IF=0;
return RCREG1;
//RCSTA1bits.CREN = 0;
//RCSTA1bits.CREN = 1;

}


can any one point out how to do it?

P.S. I'm using XC8 compiler basic.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top