I2C in interrupt (plus two bonus questions)

General discussion on mikroC.
Post Reply
Author
Message
Hamilton
Posts: 29
Joined: 24 Feb 2005 15:18

I2C in interrupt (plus two bonus questions)

#1 Post by Hamilton » 11 Jul 2006 01:28

Hello,

Why isn't it possible to use the Soft_i2c-library in an interrupt? I get "Reentrancy not allowed: function [Soft_I2C_Write] called in both main and interrupt threads", as an error message.


And the bonus questions!

1. I want something like this:

Code: Select all

void stuff_returned(char j) {
     result = 'do something with j';
}

.
.
.

result = stuff_returned(a);
Like the sub function in mBasic. Is that possible?


2. Also, there seem to be some trouble with lcd-library:

Code: Select all

// PIC16F877A 20MHz
program lcd_test

main:

TRISD = 0

Lcd_Config(PORTD,2,3,1,4,5,7,6)
Lcd_Cmd(Lcd_Clear)
Lcd_Cmd(Lcd_CURSOR_OFF)

Lcd_out(1, 1, "B!")

End.


That mBasic code works fine, but this, in mC, doesn't;

Code: Select all

// PIC16F877A 20MHz
void main() {

TRISD = 0x00;

Lcd_Config(&PORTD,2,3,1,4,5,7,6);
Lcd_Cmd(Lcd_Clear);
Lcd_Cmd(Lcd_CURSOR_OFF);

lcd_out(1, 1, "C!");

}//!
I get '3':s and other crap on the display depending on what I want it to write.

Thanks.

User avatar
milan
mikroElektronika team
Posts: 1013
Joined: 04 May 2006 16:36
Contact:

#2 Post by milan » 11 Jul 2006 11:14

Hi,

0)You can't use library function both in main and interrupt.

1)Look at the mikroC Help->mikroCLangRef->Functions->IntroductionToFunctions
You will find this example:
void polar(double x, double y, double *r, double *fi) {
*r = sqrt(x * x + y * y);
*fi = (x == 0 && y == 0) ? 0 : atan2(y, x);
return; /* this line can be omitted */
}
2)Your LCD example for C works OK.
Check the Project->EditProject settings, they should be 877A, 20MHz and Default. Also check the LCDconnections.

Hamilton
Posts: 29
Joined: 24 Feb 2005 15:18

#3 Post by Hamilton » 11 Jul 2006 16:40

milan wrote:0)You can't use library function both in main and interrupt.
Yes, I noticed that. But why? What is it that limits it to only one of them?
milan wrote:1)Look at the mikroC Help->mikroCLangRef->Functions->IntroductionToFunctions
You will find this example:
void polar(double x, double y, double *r, double *fi) {
*r = sqrt(x * x + y * y);
*fi = (x == 0 && y == 0) ? 0 : atan2(y, x);
return; /* this line can be omitted */
}
I don't know if I have understood it right, but this doesn't work:

Code: Select all

char conv(char q) {
     char u;
     if ( q == 0x00 ) { u = 0x77; }
     if ( q == 0x01 ) { u = 0x14; }
     if ( q == 0x02 ) { u = 0x3B; }
     if ( q == 0x03 ) { u = 0x3E; }
     if ( q == 0x04 ) { u = 0x5C; }
     if ( q == 0x05 ) { u = 0x6E; }
     if ( q == 0x06 ) { u = 0x6F; }
     if ( q == 0x07 ) { u = 0x74; }
     if ( q == 0x08 ) { u = 0x7F; }
     if ( q == 0x09 ) { u = 0x7E; }
     return u;
}
.
.
b = conv(a);
What is wrong?


Thanks for the help, I appreciate it!

Post Reply

Return to “mikroC General”