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

How Do You Turn Off The ECAN Module On The PIC18F4580?

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



Joined: 06 Feb 2004
Posts: 26
Location: Curitiba, Brazil

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

How Do You Turn Off The ECAN Module On The PIC18F4580?
PostPosted: Mon Aug 15, 2005 4:06 pm     Reply with quote

I am trying to gain access to the PORTB pins B2 and B3 on a PIC18F4580.

I wrote the short program below to test if I could talk to the pins, but I have had no success. I can get pins B4 through B7 to toggle but the two I/O pins B2 and B3 always stay HIGH. The data sheet says that writing to the PORTB TRIS and DATA latches can be changed if the ECAN module is active, and then refers you to that section for further info. In scanning through the 50 some pages of the ECAN section I wasn´t able to clearly understand how to turn off the ECAN module so that PORTB can be used for I/O. Has anyone seen this problem before?

Thank you.

Code:

#include <18F4580.h>
#device *=16 ADC=10

#use delay(clock=20000000)
#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT,NODEBUG

#use rs232(baud=57600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=USB)
#use i2c(MASTER, SCL=PIN_C3, SDA=PIN_C4, FORCE_HW)

#zero_ram

#use fast_io(B)

#include <can-18F4580.c>

void main()
{
   can_init();
   can_set_mode(CAN_OP_DISABLE);   //
   
      while(TRUE)
      {
      output_toggle(PIN_B2);
      delay_ms(1);
      }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 15, 2005 4:25 pm     Reply with quote

If you use fast_io mode, you need to set the TRIS for Port B with the
set_tris_b() function. If you want the compiler to automatically handle
setting the tris, then remove the #use fast_io() statement.
Bill_Smith



Joined: 06 Feb 2004
Posts: 26
Location: Curitiba, Brazil

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

PostPosted: Mon Aug 15, 2005 4:54 pm     Reply with quote

Hey PCM,

Thanks for your observation however removing that statement had no effect on my problem. Apparently there is some bit in the ECAN module still set wrong. Most of Microchip´s controller data sheets have simplified block diagrams of each of the I/O ports, the PIC18F4580 only shows a generic model, pretty difficult to track down which register is controlling the multiplexer gate.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 15, 2005 5:03 pm     Reply with quote

What happens if you comment out the calls to can_init() and can_set_mode() ?

Does Pin B2 then toggle OK ?
Bill_Smith



Joined: 06 Feb 2004
Posts: 26
Location: Curitiba, Brazil

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

PostPosted: Mon Aug 15, 2005 5:14 pm     Reply with quote

Nothing. I even tried the following:

Code:

#include <18F4580.h>
#device *=16 ADC=10

#use delay(clock=20000000)
#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NOWRT,NODEBUG

#use rs232(baud=57600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=USB)
#use i2c(MASTER, SCL=PIN_C3, SDA=PIN_C4, FORCE_HW)

#zero_ram

#byte   PORTB=0x0F81
#byte   TRISB=0x0F93

void main()
{

#asm   
   clrf PORTB;
   movlw 0b00001000;
   movwf TRISB;
#endasm

      while(TRUE)
      {
      output_toggle(PIN_B2);
      delay_ms(1);
      }
}


The debugger shows that the PORTB and TRISB bits are getting set and cleared however pin B2 refuses to toggle. Do you know if the ECAN module defaults to OFF at Power UP?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 15, 2005 5:41 pm     Reply with quote

Try adding NOPBADEN to your #fuses statement.
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