CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

migrating 18f452 to pic18LF4525 uart to EUSART problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
karth



Joined: 10 Sep 2003
Posts: 29

View user's profile Send private message

migrating 18f452 to pic18LF4525 uart to EUSART problem
PostPosted: Fri Jun 13, 2008 10:50 am     Reply with quote

guys i need some guidance with this,
I am switching mcu from 18f452 to 18LF4525

rock = 20Mhz
vdd = 3.4Vdc
ccs compiler=3.236
mplab ide= v8.0
tools= real ice

i have done 80% percent of the work... and i am stuck with the uart.
tx is working
rx not working

with the 18f452 the code was 100% working...so im pretty sure is not the code it got to do with some configuration, am i right?

any pointer???

Code:
#include <18F4525.h>
#device adc=10
#FUSES HS
#FUSES WDT                    //No Watch Dog Timer
#FUSES NOPROTECT                //Code not protected from reading
//#FUSES NOOSCSEN               //
#FUSES NOWDT                  //
#FUSES CCP2C1                 //
#FUSES NOBROWNOUT             //Reset when brownout detected
#FUSES PUT                     //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                   //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOPROTECT


#fuses HS,WDT128,NOPROTECT,PUT,NOBROWNOUT,NOLVP

#use delay(clock=20000000)
#use i2c(Master,sda=PIN_C4,scl=PIN_C3, FORCE_HW, SLOW) // hw I2C
#use rs232(baud=4800,xmit=PIN_C6,rcv=PIN_C7,bits=8,parity=N,BRGH1OK,ERRORS)
#byte LATC = 0x0F8B
#byte LATD = 0x0F8C
#byte LATE = 0x0F8D
#byte RCSTA = 0x0FAB
#bit  OERR = RCSTA.1
#bit  CREN = RCSTA.4

in the main

setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_psp(PSP_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_2(T2_DIV_BY_16,195,16);
   setup_timer_1(T1_DISABLED);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_low_volt_detect(FALSE);
   set_tris_a(0xff);
   set_tris_b(0xff);
   set_tris_c(0xbc);
   set_tris_d(0x81);
   set_tris_e(0x06);
   init_ext_eeprom();
  // write_inmem_168(MCU_INITIALS_ADDR,0xff);
   internal_mem_init();
   disable_interrupts(GLOBAL);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(INT_RB);
   enable_interrupts(INT_EXT1);
   //enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);
   GPSLOCKPIN=TRUE;
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Jun 13, 2008 11:33 am     Reply with quote

just some notes..
I went from 18F452 to 18F4525 with no problems.
I use defines
Code:
#bit  CREN =0XFAB.4
#bit  OERR =0XFAB.1
#byte RCREG=0XFAE
karth



Joined: 10 Sep 2003
Posts: 29

View user's profile Send private message

PostPosted: Fri Jun 13, 2008 1:45 pm     Reply with quote

can you copy the eusart portion of your code
thanks
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Jun 16, 2008 8:17 am     Reply with quote

sure: this is for compiler 3.249
also see
C:\Program Files\PICC\Drivers\RS485.C
C:\Program Files\PICC\Examples\EX_SISR.C
note that timer1 counts is reset when we RX a byte. Then when not receiving data counts down and indicates an idle bus.
Code:

//"startup code " disable rda till we are ready 
  disable_interrupts(INT_RDA);//disable RX
//==============================
//=====================RS485_init======================//
//Setup for RS485 communications
//init must be run before anything else
void RS485_init(void)
{
  setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
  set_timer1(Timer1_Initial_Value);
  enable_interrupts(INT_TIMER1);//this timer waits for an idle bus
  //we wait for idle bus to know that we start reading com in the right place
  CREN = 0;
  CREN = 1; //clear overflow error if something snuck in
  enable_interrupts(INT_RDA);
  if (!idle_bus)//wait for buss to go idle.  Then start reading pkt's
  {
    restart_wdt();
  }
}
//========================
//=====================tx_buffer======================//
//For transmitting data via USART and using interrupts
//must have #INT_TBE defined
void tx_buffer(char *data,int8 size)
{
  int8 x;
  disable_interrupts(INT_TBE); //so as not to change indx_i in 2 places, isr and here
  for (x=0;x<size;x++,data++)
  {
    //chksum=chksum+*data;
    TX_BUF[tx_indx_i] = *data;
    tx_indx_i++; //increment the index
    //tx_indx_i &= TXMASK;  //not needed its an int8
    if(tx_indx_o==tx_indx_i)  //if the indexs match we are full
    {
      bit_set(ERRORS,1);//set error flag bit 1 for tx overflow
      //disable_interrupts(INT_TBE);
      //tx_indx_o++;
      //tx_indx_o &= TXMASK; //not needed its an int8
    }
  }
  enable_interrupts(INT_TBE);
  return;
}

//=======================TXisr============================//
//Takes data from buffer and puts it into a TX stream (RS485)
//uses interrupts to empty buffer at proper rate
#INT_TBE
void TXisr(void)
{
  CREN = 0;
  idle_bus=FALSE;
  fputc(TX_BUF[tx_indx_o],RS485);
  tx_indx_o++;      //not used//tx_indx_o &= TXMASK;
  if(tx_indx_o==tx_indx_i)
  {
    disable_interrupts(INT_TBE);
    CREN = 1;
  }
}

//=======================RXisr============================//
//Takes RX data from a stream and puts it into a buffer via interrupts
#INT_RDA
void RXisr(void)
{
  idle_bus=FALSE;
  set_timer1(Timer1_Initial_Value);
  RX_BUF[rx_indx]=RCREG;
  rx_indx++;
  if (rx_indx==MAXHEADER+MAXDATA+1) // check for buffer overflow
  {
    bit_set(ERRORS,2);//set error flag bit 2 for RXbuffer overflow
  }
  if (OERR)
  {
    bit_set(ERRORS,0);//set error flag bit 0 for USART overflow
    CREN = 0;
    CREN = 1;
  }
}

//=======================checksum============================//
int8 chksum(char *data,int8 size)
{
  int8 x;
  int8 chksum=0;
  for (x=0;x<size;x++,data++)
  {
    chksum=chksum+*data;
    //fprintf(DEBUG,".");
  }
  return(chksum);
}
karth



Joined: 10 Sep 2003
Posts: 29

View user's profile Send private message

PostPosted: Mon Jun 16, 2008 1:27 pm     Reply with quote

i am using Asynchronous mode and the compiler i am using is 3.236 is that compatible with pic18lf4525???
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Jun 17, 2008 8:03 am     Reply with quote

It could be the compiler version, or something to do with the "LF" version
of the chip.
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Tue Jun 17, 2008 12:21 pm     Reply with quote

Check the specs for the part that you are using. Look at figure 26-3 in the latest data sheet. There is a formula for max operating frequency vs supply voltage. If I am not mistaken, using this formula, the max operating frequency is 18.9MHz at 3.4v. If you are making a one off project, you might get lucky and get away with this. If this is a commercial product, you might consider some changes.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Jun 17, 2008 2:33 pm     Reply with quote

I never caught that he was running at that low of a voltage. Good catch.
karth



Joined: 10 Sep 2003
Posts: 29

View user's profile Send private message

PostPosted: Wed Jun 18, 2008 7:59 am     Reply with quote

i spoke to microchip, for 3.5 v 20mhz rock is fine....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group