Clicker 2 and I2C

General discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
rfcan
Posts: 5
Joined: 04 Jan 2021 02:54

Clicker 2 and I2C

#1 Post by rfcan » 04 Jan 2021 07:46

Hello,

I'm using your Clicker 2 development board (PIC24FJ1024GB610 µC). I'm exploring it bit by bit by trying simple routines.

Recently, I tried I2C2_Init/Start/Write/Read/Stop and those functions work well.

I would like to know what code is behind each of those fonctions?

I tried to program an Init + Start + Write(slave address) + Write (control byte) + Write (data byte) + Stop without using mikroC's functions, but this simple routine is conflicting with my USB port. See below:

void main(){

I2C2BRG = 0x26; // Fosc 100 kHz
I2C2CONL= 0x0000; // Clear register

Delay_100ms();

while(1){

if (!I2C2_Is_Idle){
I2C2CONL= 0x8001; // start
}

if (!I2C2_Is_Idle){
I2C2TRN = 0x92; // write PCF8591 address
}

if (!I2C2_Is_Idle){
I2C2TRN = 0x40; // write PCF8591 control byte
}

if (!I2C2_Is_Idle){
I2C2TRN = 0xB0; // write data (50% of 5 VDC)
}

if (!I2C2_Is_Idle){
I2C2CONL= 0x8004; // stop
}

Delay_100ms();
}
}

What seems wrong with my code above? As an FYI: I'm using the RA2(SCL) and RA3 (SDA) lines. 10k pull-up resistors on each line.

Thanks,
RF Can

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Clicker 2 and I2C

#2 Post by filip » 04 Jan 2021 17:15

Hi,
I would like to know what code is behind each of those fonctions?
Unfortunately, due to the company's policy I'm not in liberty to share the library source codes, thank you for the understanding.

Can you debug your code via hardware debugger and see if it hangs somewhere ?

Regards,
Filip.

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 General”