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 CCS Technical Support

Problem PIC18F4550 + ENC28J60 + DS1621 between SPI and I2C

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



Joined: 18 Oct 2012
Posts: 3

View user's profile Send private message

Problem PIC18F4550 + ENC28J60 + DS1621 between SPI and I2C
PostPosted: Thu Oct 18, 2012 4:00 pm     Reply with quote

Hi all, I'm new in the site and I have a problem that I don't know how to get out of it, I have run out of ideas and someone can help me.

I use CCS C + PIC18F4550 + ENC28J60 DS1621 and all done with the MPLAB IDE.

I'm implementing a PIC18F4550 with ENC28J60 Ethernet peripheral in the micro I have hosted a simple website, only to test, until then everything goes perfect.

The problem come when I attempting to add one more peripheral via the I2C protocol, I try to connect a temperature sensor (DS1621) but the system crashes.

when the system reads the line i2c_start(); the program enters in #use i2c(.....) and crashes.

I've been running the code in debugger mode via an ICD2 and upon reaching #use i2c (...) enters the routine protocol and is jumping between two records.
I upload a photo:



The records are:
Code:
BTFSS 0xf82 , 05 ACESS


and
Code:
BRA 0x462


And hence not come out, whereupon the program is interrupted.

I tried with SPI hardware and software and in both cases the same thing happens

I don't know if this is a compiler bug or I did forget add something to code.

I know the problem is with the ENC28J60 driver because I delete the whole program and I've only left the driver of the ENC and a only function and when work the I2C routine happen the same.

copy and paste the main routine:

Code:
#include <18F4550.h>
#fuses HSPLL,MCLR,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN   // Ocupa cristal 4Mhz, cambiar a PLL5 para ocuparlo con 20Mhz.
#use delay(clock=48000000)

#define  ON    output_high
#define  OFF   output_low

#define  LedV  PIN_A3
#define  LedR  PIN_A4

// Conexión entre el PIC18F4550 y el Modulo ENC28J60 (Se conecta directamente sin adaptador de voltajes).
// Se adjunta el datasheet del Modulo ENC28J60.

#ifndef  PIN_ENC_MAC_SO
#define  PIN_ENC_MAC_SO    PIN_C7   // Conectar con PIN MISO del ENC28J60.
#define  PIN_ENC_MAC_SI    PIN_B4   // Conectar con PIN MOSI del ENC28J60.
#define  PIN_ENC_MAC_CLK   PIN_B2   // Conectar con PIN SCK del ENC28J60.
#define  PIN_ENC_MAC_CS    PIN_B3   // Conectar con PIN CS del ENC28J60.
#define  PIN_ENC_MAC_RST   PIN_B5   // Conectar con PIN RST del ENC28J60.
#define  PIN_ENC_MAC_INT   PIN_D2   // Conectar con PIN INT del ENC28J60.
#define  PIN_ENC_MAC_WOL   PIN_D3   // Conectar con PIN WOL del ENC28J60.
#define mac_enc_spi_tris_init()  *0xF93=*0xF93 | 7; *0xF95=*0xF95 & 0xF0
#endif

#ifndef ENC_MAC_USE_SPI
#define ENC_MAC_USE_SPI TRUE
#endif

#include "Drivers/enc28j60.c"

#ifndef DAL_SCL
#define DAL_SCL PIN_C5
#define DAL_SDA PIN_C4
#endif
#include "Drivers/DS1621M.C"

void main(void){
   int16 dato;
   ON(LedR);
   OFF(LedV);

mac_spi_init();
mac_reg_init();
init_temp(0x00);

   while(TRUE){     
   ON(LedR);
   delay_ms(50);
   OFF(LedR);
   delay_MS(50);
   dato=enc_mac_read_phy_word(0x00);
   }
}


the driver of the ENC and the DS1621 are in PICC directory.

Sorry my poor english and thanks for all
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 18, 2012 4:45 pm     Reply with quote

Quote:

#include <18F4550.h>

#ifndef DAL_SCL
#define DAL_SCL PIN_C5
#define DAL_SDA PIN_C4
#endif
#include "Drivers/DS1621M.C"

Look up pins C4 and C5 in the Overview section of the 18F4550 data sheet. What can those pins do ?
Thulsa-Doom



Joined: 18 Oct 2012
Posts: 3

View user's profile Send private message

PostPosted: Fri Oct 19, 2012 3:03 am     Reply with quote

I have used these pins for I2C protocol software, but doesn't work.

I changed the pins, I used the pins SDA to B0 and SCL to B1, as written in the datasheet, these are the pins on the PIC18F4550 in I2C protocol and does not work.


I implemented the code for software in ENC28J60 leaving the pins B0 and B1 free for i2c and no work.

I implemented the code by software at all protocols and no work.

The codes work fine by separate.

I blocked I can't think of anything more
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Fri Oct 19, 2012 3:49 am     Reply with quote

The original pins are never going to work. If you look at the data sheet, C4, and C5, are _input only_ when used for normal applications. They don't support output, so cannot be used to drive I2C. This is what PCM programmer pointed you to.

Now, obvious comment, what is your pull up resistor value?. As you add more devices, the I2C bus gets longer, and has more capacitance. The required pull up decreases. If you are using a high value like 4K7, then you need to come down significantly. I'd suggest 1K2.

On the B0, & B1 pins, add the fuse NOPBADEN, or port B wakes up setup for ADC operation.

Hardware I2C, uses Schmitt trigger input buffers, so with these pins, having adequate pull up on the bus becomes even more important. Applies even if you use the 'software' library.

Best Wishes
Thulsa-Doom



Joined: 18 Oct 2012
Posts: 3

View user's profile Send private message

PostPosted: Fri Oct 19, 2012 1:34 pm     Reply with quote

Well thanks for the help, the problem was the pull-up resistors.

I used the pins B2 and B4 for the I2C protocol, forced by hardware protocol and I installed a pull-up resistors and now works fine.

thank you very much
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