|
|
View previous topic :: View next topic |
Author |
Message |
daraos
Joined: 16 Oct 2008 Posts: 18 Location: Chile
|
I2C: 18f2550 master and 30f3013 slave, won't work |
Posted: Wed Sep 15, 2010 8:43 am |
|
|
I'm using a PIC18f2550 as a master and a dsPIC30f3013 as a slave, and the interrupt in the slave never triggers.
I started 2 new projects leaving the code at its bare minimum.
The oscilloscope shows the data and the clock correctly, but the pin_f6 never goes high. I've tried with force_hw and force_sw in the master.
This is the code for the master:
Code: |
#include<18F2550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,nomclr, put
#use delay(clock=48000000)
#use i2c(master, I2C1, slow, force_hw)
void main(){
byte data_i2c;
while(TRUE){
i2c_start();
i2c_write(0xB0);
i2c_write(data_i2c);
i2c_write(0x00); //dummy, segundo byte que se envia a dspic
i2c_start();
i2c_write(0xB1);
data_i2c=i2c_read(0);
i2c_stop();
delay_ms(5000);
}
}
|
and the code for the slave:
Code: |
#include<30f3013.h>
byte channel,cama;
#fuses frc_pll16, nowdt, nodebug, nomclr, nobrownout, noprotect
#use i2c(SLAVE, I2C1, address=0xB0, force_hw)
#INT_SI2C
void ssp_interupt ()
{
BYTE state, incoming;
state = i2c_isr_state();
output_high(pin_f6); //to check if the interrupt triggers
if(state <= 0x80){ //Master is sending data
incoming = i2c_read(0);
if(state == 1){ //First received byte is address
channel = incoming;
}
else if(state == 2){ //Second received byte is data
cama = incoming;
}
}
if(state == 0x80){ //Master is requesting data
i2c_write(0x55);
}
}
void main(){
//initial setup
output_low(pin_f6);
enable_interrupts(INT_SI2C);
enable_interrupts(INTR_GLOBAL);
while(TRUE){}
}
|
I have 3 days now trying to solve this, please help! |
|
|
daraos
Joined: 16 Oct 2008 Posts: 18 Location: Chile
|
|
Posted: Thu Sep 16, 2010 10:41 am |
|
|
I don't know why, but I solved it changing the Master Address to 0x60, and the Slave answer at the address 0xB0. Really weird, probably because I'm using a invalid address for the slave or something like that. I'll look into it once I'm finished with the project.
Also, in the slave's interrupt routine, I changed
Code: | if(state <= 0x80){ //Master is sending data |
with
Code: | if(state < 0x80){ //Master is sending data |
and works perfectly |
|
|
|
|
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
|