bonjour tous le monde
je souhaite communiquer en i2c avec mon pic . Mais a la sortie lorsque je regarde ma clock je vois un signal +5v.j ai mit des résistance de pull up de 4.7k.
J'utilise un PIC 18f4550, MPLAB v8, un programmateur ICD 2 et la librairie i2c.h.
je voudrai savoir si mon initialisation est correcte...
void UserInit(void)
{
byte i;
//Input/output pins
tris_CS = 1; //Input, not used for I2C
TRISBbits.TRISB0 = 1; //SDA
TRISBbits.TRISB1 = 1; //SCL
//Setup I2C registers
I2C_xfer_done = FALSE;
SSPADD = 0xC0; //I2C address of this micro
PIE1bits.SSPIE = 0; //Turn off I2C/SPI interrupt
PIR1bits.SSPIF = 0; //Clear any pending interrupt
OpenI2C(SLAVE_7,SLEW_ON);
PIE1bits.SSPIE = 1; //Turn on I2C interrupt
//-------------------------
// initialize variables
//-------------------------
for (i=0; i<BUF_SIZE; i++) // initialize input and output buffer to 0
{
inbuffer[i]=0;
outbuffer[i]=0;
}
TimerCounter = 0xF0; //Initial value to start
//Timer 0
TMR0H = 0; //clear timer
TMR0L = 0; //clear timer
T0CONbits.PSA = 0; //Assign prescaler to Timer 0
T0CONbits.T0PS2 = 1; //Setup prescaler
T0CONbits.T0PS1 = 1; //Will time out every 51 us based on
T0CONbits.T0PS0 = 1; //20 MHz Fosc
T0CONbits.T0CS = 0; //Increment on instuction cycle
//Enable I2C interrupts
INTCONbits.PEIE = 1; //Turn on peripheral interrupts
INTCONbits.GIE = 1; //Turn on global interrupts
}
MessagePosté le: Lun 28 Avr 2008, 08:07 Sujet du message: 18f4550 i2c Répondre en citant Editer/Supprimer ce message
bonjour tous le monde
je souhaite communiquer en i2c avec mon pic . Mais a la sortie lorsque je regarde ma clock je vois un signal +5v.j ai mit des résistance de pull up de 4.7k.
je voudrai savoir si mon initialisation est correcte...
Code:
void UserInit(void)
{
byte i;
//Input/output pins
tris_CS = 1; //Input, not used for I2C
TRISBbits.TRISB0 = 1; //SDA
TRISBbits.TRISB1 = 1; //SCL
//Setup I2C registers
I2C_xfer_done = FALSE;
SSPADD = 0xC0; //I2C address of this micro
PIE1bits.SSPIE = 0; //Turn off I2C/SPI interrupt
PIR1bits.SSPIF = 0; //Clear any pending interrupt
OpenI2C(SLAVE_7,SLEW_ON);
PIE1bits.SSPIE = 1; //Turn on I2C interrupt
//-------------------------
// initialize variables
//-------------------------
for (i=0; i<BUF_SIZE; i++) // initialize input and output buffer to 0
{
inbuffer[i]=0;
outbuffer[i]=0;
}
TimerCounter = 0xF0; //Initial value to start
//Timer 0
TMR0H = 0; //clear timer
TMR0L = 0; //clear timer
T0CONbits.PSA = 0; //Assign prescaler to Timer 0
T0CONbits.T0PS2 = 1; //Setup prescaler
T0CONbits.T0PS1 = 1; //Will time out every 51 us based on
T0CONbits.T0PS0 = 1; //20 MHz Fosc
T0CONbits.T0CS = 0; //Increment on instuction cycle
//Enable I2C interrupts
INTCONbits.PEIE = 1; //Turn on peripheral interrupts
INTCONbits.GIE = 1; //Turn on global interrupts
}
la fonction processio est appelé en boucle dans le Main
Code:
void ProcessIO(void)
{
StartI2C();
WriteI2C(0xA0);
WriteI2C(0xF0);
StopI2C();
}
merci a vous .
-----