|
|
View previous topic :: View next topic |
Author |
Message |
Bill_Smith
Joined: 06 Feb 2004 Posts: 26 Location: Curitiba, Brazil
|
How Do You Turn Off The ECAN Module On The PIC18F4580? |
Posted: Mon Aug 15, 2005 4:06 pm |
|
|
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
|
|
Posted: Mon Aug 15, 2005 4:25 pm |
|
|
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
|
|
Posted: Mon Aug 15, 2005 4:54 pm |
|
|
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
|
|
Posted: Mon Aug 15, 2005 5:03 pm |
|
|
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
|
|
Posted: Mon Aug 15, 2005 5:14 pm |
|
|
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
|
|
Posted: Mon Aug 15, 2005 5:41 pm |
|
|
Try adding NOPBADEN to your #fuses statement. |
|
|
|
|
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
|