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

New I2C trouble, 18f4550 master versus 18f2550 slave.

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



Joined: 27 Feb 2007
Posts: 17

View user's profile Send private message

New I2C trouble, 18f4550 master versus 18f2550 slave.
PostPosted: Sun Mar 04, 2007 6:48 pm     Reply with quote

Master: 18f4550 @48mhz / 20mhz xtal
Code:

#include <18f4550.h>
#fuses HS,PLL5,CPUDIV1,NOWDT,PUT,NOLVP
#use delay(clock=48000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#build (reset=0x04,interrupt=0x08)

int encoder_value=0,encoder_target=0;
int1 encoder_bit=0,encoder_bit2=0,encoder_task=0;

int motortask;


#include <lcdbot.c>
#use i2c(master, sda=PIN_C4,scl=PIN_C5,slow)

int i2c_data[10];
int tmp;
int q;


void main()
{
setup_psp(PSP_DISABLED);
set_tris_c(0x00);
output_low(PIN_C4);
output_low(PIN_C5);
set_tris_c(0x30);



//setup_timer_0 (RTCC_INTERNAL|RTCC_DIV_4);
//enable_interrupts(GLOBAL);
//enable_interrupts(INT_TIMER0);
lcd_init();
printf(LCD_PUTC,"START!!");
delay_ms(1000);
lcd_putc('\f');

while(1)
{

printf(LCD_PUTC,"Start2");
delay_ms(1000);
lcd_putc('\f');

i2c_start();
printf(LCD_PUTC,"1");
delay_ms(1);
i2c_write(0xa0);
printf(LCD_PUTC,"2");
delay_ms(1);
i2c_write(0x00);
printf(LCD_PUTC,"3");
delay_ms(1);
i2c_write(0x80);
printf(LCD_PUTC,"Datos");
lcd_putc('\f');
i2c_stop();

printf(LCD_PUTC,"Dato enviado");

delay_ms(1000);
lcd_putc('\f');

i2c_start();
i2c_write(0xa0);
i2c_write(0x00);
i2c_start();
i2c_write(0xa1);
tmp=i2c_read();
printf(LCD_PUTC,"%u",tmp);
i2c_stop();

}

}



I think slave code is not necessary at this moment, for the reasons i'm explaining now. The chip starts working, shows START!!! , START2, and then shows 1. And then nothing happens. The chip hung. So the thing gets hung in i2c_write, i suppose. It's not possible to use hardware MSSP, because of the needed pinout.

I've looked into the problem with an analogic scope, and i found out that both SDA and SCL stay high all the time. 2K2 pullups are used.

I hope you can help me.
unnamedplayer
Guest







PostPosted: Mon Mar 05, 2007 4:19 pm     Reply with quote

i heard hardware ssp gives less trouble than soft one..
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Mar 05, 2007 5:55 pm     Reply with quote

Odds are, if you are using another PIC as the slave, the code inside it is not working properly. The slave can hold the I2C bus in a 'busy' state and the master will just set there twiddling it's thumbs until it is released. Look through this forum and look for the many examples for slaves. Try a few and see if you can get them to work. Then, once you find one that works, modify it little-by-little until you have it doing what you want.

Ronald
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Mon Mar 05, 2007 7:27 pm     Reply with quote

Dont know whether it helps, but fuse should be HSPLL instead of HS.
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