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

PIC18F4550 bugs again & again !?

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



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PIC18F4550 bugs again & again !?
PostPosted: Wed Jul 04, 2007 6:28 am     Reply with quote

Hey to all,

I've noticed that PORTB[0] behaves weirdly. when i write a value to PORTB, RB0 sometimes is correct some other times is not. At first i thought that the PIC is damaged until i tried another one. Same problem!
Code:
PORTB = Buff[i];

Going through the listing i've noticed that the instruction used is MOVFF


Any comments? Shocked
Ttelmah
Guest







PostPosted: Wed Jul 04, 2007 8:29 am     Reply with quote

Every pin on portB, on that chip, has other devices multiplexed onto it. Are all these disabled?...

Best Wishes
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Wed Jul 04, 2007 8:44 am     Reply with quote

Yes of course...

Code:

#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN, NOPBADEN, ICPRT
...
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
...
set_tris_b(0x00);


Anything else?

10x
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 04, 2007 1:48 pm     Reply with quote

1. Post a short, compilable test program that demonstrates the problem.
Show all #include, #use, #device, and #fuses statements.
Show all data declarations.

2. Post your compiler version.
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Thu Jul 05, 2007 12:36 am     Reply with quote

Compiler: 4.029

Code:

#include <18F4550.h>
#device adc=8

#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN, NOPBADEN, ICPRT
#use delay(clock=48000000)

#byte PORTA = 0xF80
#byte PORTB = 0xF81
#byte PORTC = 0xF82
#byte PORTD = 0xF83
#byte PORTE = 0xF84
#byte TRISE = 0xF96

// USB
#include <usb_cdc.h>
///////////////////////////////////////////////////////////////////////////////
#define  SetData(X)  PORTB = X
#define  GetData()   PORTB

#bit     SS =  PORTE.0
#bit     SG =  PORTE.1
#bit     RW =  PORTE.2
#bit     DR =  PORTC.2

#define  isSPI()     bit_test(Buff[1],7)
#define  Finalize()  (!bit_test(Buff[1],6))
#define  isREAD()    bit_test(Buff[2],7)
///////////////////////////////////////////////////////////////////////////////
void SetCSR(int16 CSRData)
{
   PORTD = CSRData & 0xFF;
   PORTA = CSRData >> 8;
}
///////////////////////////////////////////////////////////////////////////////
#use delay(clock=48000000)
///////////////////////////////////////////////////////////////////////////////
void main()
{
   unsigned int8 Buff[132];
   unsigned int8 BuffPointer=0;
   unsigned int8 DataLen=0;
   unsigned int8 i;
   
   PORTA = 0x00;
   PORTB = 0x00;
   PORTC = 0x00;
   PORTD = 0x00;
   PORTE = 0x01;
   set_tris_a(0x00);
   set_tris_b(0x00);
   set_tris_c(0xFE);
   set_tris_d(0x00);
   set_tris_e(0x00);
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
 
   setup_low_volt_detect(FALSE);
   setup_oscillator(False);

   delay_ms(1000);
   
//////////////////////////////////////////////////////////////
   usb_cdc_init();
   usb_init();
   while(!usb_cdc_connected()) {}
   
   while (TRUE)
   {
      usb_task();
      if (usb_enumerated())
      {
         Buff[BuffPointer++] = usb_cdc_getc();
         if (BuffPointer == 3) // check for data length
            DataLen = Buff[BuffPointer-1] & 0x7F;
         if ((BuffPointer == DataLen + 3) || ((BuffPointer == 3) && (isREAD())))
         {   //end of buffer?
            switch (Buff[0])
            {
               case 0xFF:     // Data <-->     
                  if (isREAD())     //read
                  {
                     set_tris_b(0xFF); // input
                     RW = 1;
                     if (isSPI())// SPI
                     {
                        SetCSR(0x100 | (Buff[1] & 0x3F));
                        SS = 0;
                        for (i=0;i<DataLen;i++)
                        {
                           SG = 1;
                           delay_us(3);
                           SG = 0;
                           while(!DR); //wait for DR
                           usb_cdc_putc(GetData());   // send data to pc
                        }
                        SS = 1;
                     }
                     else        // I2C
                     {
                        SetCSR(Buff[1] & 0x7F);
                        SS = 0;
                        while(!DR); //wait for DR
                        for (i=0;i<DataLen;i++)
                        {
                           SG = 1;
                           delay_us(3);
                           SG = 0;
                           while(!DR); //wait for DR
                           usb_cdc_putc(GetData());   // send data to pc
                        }
                        SS = 1;
                     }
                  }
                  else              //write
                  {
                     set_tris_b(0x00); //  output
                     RW = 0;
                     if (isSPI())// SPI
                     {
                        SetCSR(0x100 | (Buff[1] & 0x3F));
                        SS = 0;
                        for (i=0;i<DataLen;i++)
                        {
                           //SetData(Buff[3+i]);
                           PORTB = Buff[3+i];      // PROBLEM in RB0 ///////////////////////////////
                           SG = 1;
                           delay_us(3);
                           SG = 0;
                           while(!DR); //wait for DR
                        }
                        if (Finalize())
                           SS = 1;
                     }
                     else        // I2C
                     {
                        SetCSR(Buff[1] & 0x7F);
                        SS = 0;
                        while(!DR); //wait for DR
                        for (i=0;i<DataLen;i++)
                        {
                           //SetData(Buff[3+i]);
                           PORTB = Buff[3+i];      // PROBLEM in RB0 ///////////////////////////////
                           SG = 1;
                           delay_us(3);
                           SG = 0;
                           while(!DR); //wait for DR
                        }
                        SS = 1;
                     }
                  }
               break;
                 
               case 0xAA:  // Command (reserved)
                 
               break;
            }
            BuffPointer = 0;     // reset pointer
            DataLen = 0;         // clear data length
         }
      }
   }
}


Everything works poerfect except for the lines commented with "// PROBLEM in RB0 ///////////////////////////////"

Shocked


Last edited by PICoHolic on Thu Jul 05, 2007 1:29 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 05, 2007 12:44 am     Reply with quote

I wouldn't call that a short test program.
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Thu Jul 05, 2007 12:53 am     Reply with quote

Dont worry about all the code.
Just the commented one.
10x
Ttelmah
Guest







PostPosted: Thu Jul 05, 2007 3:15 am     Reply with quote

I would add a couple of things:
CCP2C1
Otherwise CCP2 is multiplexed onto portB
Also note that the USB peripheral is multiplexed onto RB2 & 3, while RB4 is the SPP CS pin. I'd probably explicitly clear SPPEN to ensure this is not causing a problem.
Also, if you want to control the TRIS yourself, and write directly to the port, use #use fast_io(B) otherwise the compiler will still think that _it_ has control of the port direction register, and may override what you are doing.
As a comment, why not use the output_b instruction?.

Best Wishes
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Thu Jul 05, 2007 3:29 am     Reply with quote

1- CCP2C1 is added by default:
Code:

Configuration Fuses:
   Word  1: 0E24   NOIESO NOFCMEN HSPLL PLL5 CPUDIV1 USBDIV
   Word  2: 1E38   NOBROWNOUT NOWDT BORV20 PUT WDT32768 VREGEN
   Word  3: 8100   NOPBADEN CCP2C1 MCLR NOLPT1OSC RESERVED
   Word  4: 00A1   STVREN NODEBUG NOLVP NOXINST ICPRT
   Word  5: C00F   NOPROTECT NOCPD NOCPB
   Word  6: E00F   NOWRT NOWRTD NOWRTC NOWRTB
   Word  7: 400F   NOEBTR NOEBTRB


2- SSPEN is cleared:
Code:

....................    setup_spi(FALSE);
10CC:  BCF    FC6.5        <---
10CE:  BCF    F94.7
10D0:  BSF    F93.0
10D2:  BCF    F93.1
10D4:  MOVLW  00
10D6:  MOVWF  FC6
10D8:  MOVWF  FC7


I still have to try the output_b function ..

10x anyway
Ttelmah
Guest







PostPosted: Thu Jul 05, 2007 4:04 am     Reply with quote

SPPEN, not SSPEN
The latter is the SPI connection. The fmer is the synchronous parallel port CS.

Best Wishes
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