Hi,
I am trying to use SW I2C on PIC12F683 but can't ?
The line for configuration the PORTS (SDA and SCL) are:
Soft_I2C_Config(&GPIO,1,3);
May be the Soft_I2C_Config doesn't recognize GPIO, and it only "understand" : Soft_I2C_Config(&PORTA,1,3); or PORTB etc?
Did any one try to use the Soft_I2C_Config on PIC12F683?
Thanks,
Roee.
Software I2C doesn't work when trying it on PIC12F683 ? help
Re: Software I2C doesn't work when trying it on PIC12F683 ?
Hi,
When you type GPIO, PORTA ... compiler looks at the MCU definition files,
in your case ...\mikroC PRO for PIC\defs\P12F683.c
You can use all the registers, bits and constants defined in this file.
------------------------------------------------------------------
You have to be very careful with 8-pin MCUs, they have small number of I/O pins and they are multiplexed with other functions.
When you are trying to use some pins as digital I/O :
1. Check ADC input functions and turn off AN input mode
2. Check comparators functions and turn off comparator mode
3. Check everything else that can disable digital I/O function of the pin
See datasheet for PIC12F683 -> TABLE 1-1: PIC12F683 PINOUT DESCRIPTION
1. You used GP1, it has analog input function. Read about ANSEL register to turn this function off. Check the comparators too.
2. You used GP3 pin
This pin is multiplexed with MCLR function. You must turn it off. This is done by setting configuration words.
Open EditProjcet window in the compiler and set "MCLR Enabled" option to Internal(Disabled).
But this is not enough. Datasheet states : "GPIO input with interrupt-on-change", when you make it digital, it is not I/O pin, it's just Input pin.
My advice to you is to choose some other pins for Soft_I2C (perhaps GP0 and GP1) and read the datasheet carefully.
No it can work with all kind of ports.roee wrote: May be the Soft_I2C_Config doesn't recognize GPIO, and it only "understand" : Soft_I2C_Config(&PORTA,1,3); or PORTB etc?
When you type GPIO, PORTA ... compiler looks at the MCU definition files,
in your case ...\mikroC PRO for PIC\defs\P12F683.c
You can use all the registers, bits and constants defined in this file.
------------------------------------------------------------------
You have to be very careful with 8-pin MCUs, they have small number of I/O pins and they are multiplexed with other functions.
When you are trying to use some pins as digital I/O :
1. Check ADC input functions and turn off AN input mode
2. Check comparators functions and turn off comparator mode
3. Check everything else that can disable digital I/O function of the pin
Code: Select all
Soft_I2C_Config(&GPIO,1,3);
1. You used GP1, it has analog input function. Read about ANSEL register to turn this function off. Check the comparators too.
2. You used GP3 pin
This pin is multiplexed with MCLR function. You must turn it off. This is done by setting configuration words.
Open EditProjcet window in the compiler and set "MCLR Enabled" option to Internal(Disabled).
But this is not enough. Datasheet states : "GPIO input with interrupt-on-change", when you make it digital, it is not I/O pin, it's just Input pin.
My advice to you is to choose some other pins for Soft_I2C (perhaps GP0 and GP1) and read the datasheet carefully.
SmartADAPT2 rules !
Hi, and thanks, I have changed to GP1 and GP2
Here is my code ...
Can you advice how to change it?
This code works fine in another microchip.
Should I define TRISIO?? (or it might block softi2c?).
Thanks,
Roee.
//main
i2c_mess_const (const char *s,int line,int clean); //message to LCD
I2C_mess(char message[],int line,int clean);
I2C_mess_specific_place(char message[],unsigned char pos);
main()
{
char message[] = "Ultrasonic By Roee.";
char message1[] = "Timer1 is:";
char lcd;
lcd=1;
INTCON=0;
TRISIO = 0x21; // bit 5,0 is in
//led blinks
while(1)
{
GPIO = 0x10;
delay_ms(200);
GPIO=0;
delay_ms(200);
GPIO = 0x10;
delay_ms(200);
GPIO=0;
delay_ms(1000);
I2C_mess(message,1,1);
}
return 1;
}
// i2c_message
//#ifdef LCDON
// this procedure will send message to LCd
send_lcd_char_const(const char message[20]);
send_lcd_char(char message[]) ;
light_lcd(char lit);
send_lcd_clear();
lcd_line2();
I2C_mess_const(const char message[],int line,int clean)
{
// INTCON =0;
// take GP1(pin 6) and GP2(pin5) - first SDA second SCL
Soft_I2C_Config(&GPIO,2,1); // init soft I2C pin 5=data and pin 4=clock
if (clean==1) send_lcd_clear();
//clear and home
light_lcd(0); // 0 for light on
if (line==2) lcd_line2();
send_lcd_char_const(message);
return 1;
// INTCON = 255;
}
I2C_mess(char message[],int line,int clean)
{
// INTCON =0;
Soft_I2C_Config(&GPIO,2,1); // init soft I2C
if (clean==1) send_lcd_clear(); //clear and home
light_lcd(0); // 0 for light on
if (line==2) lcd_line2();
send_lcd_char(message);
return 1;
// INTCON =255;
}
I2C_mess_specific_place(char message[],unsigned char pos)
{
// INTCON =0;
Soft_I2C_Config(&GPIO,2,1); // init soft I2C
light_lcd(0); // 0 for light on
pos = pos+128;
Soft_I2C_Start (); //send start bit
Soft_I2C_Write(0x42); //LCD address
Soft_I2C_Write(0x1); //Command
Soft_I2C_Write(pos);
Soft_I2C_Stop(); //send stop bit
send_lcd_char(message);
return 1;
// INTCON=255;
}
send_lcd_char_const(const char message[]) // this one send string to LCD
{
int i=0;
Soft_I2C_Start (); //send start bit
Soft_I2C_Write(0x42); //LCD address
Soft_I2C_Write(2); //write to I2c
//start string
while (message){ // write all string to LCD
Soft_I2C_Write(message[i++]);
}
Soft_I2C_Stop(); //send stop bit
return 1;
}
send_lcd_char(char message[]) // this one send string to LCD this one for variables chars
{
int i=0;
Soft_I2C_Start (); //send start bit
Soft_I2C_Write(0x42); //LCD address
Soft_I2C_Write(2); //write to I2c
//start string
while (message){ // write all string to LCD
Soft_I2C_Write(message[i++]);
}
Soft_I2C_Stop(); //send stop bit
return 1;
}
send_lcd_clear() // clear and home
{
Soft_I2C_Start (); //send start bit
Soft_I2C_Write(0x42); //LCD address
Soft_I2C_Write(1); //write to I2c
Soft_I2C_Write(1); //write to I2c
Soft_I2C_Stop(); //send stop bit
return 1;
}
light_lcd(char lit)
{
Soft_I2C_Start (); //send start bit
Soft_I2C_Write(0x42); //LCD address
Soft_I2C_Write(3); //write to I2c
if (lit==1) // light off
Soft_I2C_Write(1); //write to I2c
else // light on
Soft_I2C_Write(0); //write to I2c
Soft_I2C_Stop(); //send stop bit
return 1;
}
lcd_line2()
{ //command A8 from http://www.doc.ic.ac.uk/~ih/doc/lcd/instruct.html
Soft_I2C_Start (); //send start bit
Soft_I2C_Write(0x42); //LCD address
Soft_I2C_Write(0x1); //Command
Soft_I2C_Write(0xc0);
Soft_I2C_Stop(); //send stop bit
return 1;
}
// #endif
Thanks,
Roee.
Can you advice how to change it?
This code works fine in another microchip.
Should I define TRISIO?? (or it might block softi2c?).
Thanks,
Roee.
//main
i2c_mess_const (const char *s,int line,int clean); //message to LCD
I2C_mess(char message[],int line,int clean);
I2C_mess_specific_place(char message[],unsigned char pos);
main()
{
char message[] = "Ultrasonic By Roee.";
char message1[] = "Timer1 is:";
char lcd;
lcd=1;
INTCON=0;
TRISIO = 0x21; // bit 5,0 is in
//led blinks
while(1)
{
GPIO = 0x10;
delay_ms(200);
GPIO=0;
delay_ms(200);
GPIO = 0x10;
delay_ms(200);
GPIO=0;
delay_ms(1000);
I2C_mess(message,1,1);
}
return 1;
}
// i2c_message
//#ifdef LCDON
// this procedure will send message to LCd
send_lcd_char_const(const char message[20]);
send_lcd_char(char message[]) ;
light_lcd(char lit);
send_lcd_clear();
lcd_line2();
I2C_mess_const(const char message[],int line,int clean)
{
// INTCON =0;
// take GP1(pin 6) and GP2(pin5) - first SDA second SCL
Soft_I2C_Config(&GPIO,2,1); // init soft I2C pin 5=data and pin 4=clock
if (clean==1) send_lcd_clear();
//clear and home
light_lcd(0); // 0 for light on
if (line==2) lcd_line2();
send_lcd_char_const(message);
return 1;
// INTCON = 255;
}
I2C_mess(char message[],int line,int clean)
{
// INTCON =0;
Soft_I2C_Config(&GPIO,2,1); // init soft I2C
if (clean==1) send_lcd_clear(); //clear and home
light_lcd(0); // 0 for light on
if (line==2) lcd_line2();
send_lcd_char(message);
return 1;
// INTCON =255;
}
I2C_mess_specific_place(char message[],unsigned char pos)
{
// INTCON =0;
Soft_I2C_Config(&GPIO,2,1); // init soft I2C
light_lcd(0); // 0 for light on
pos = pos+128;
Soft_I2C_Start (); //send start bit
Soft_I2C_Write(0x42); //LCD address
Soft_I2C_Write(0x1); //Command
Soft_I2C_Write(pos);
Soft_I2C_Stop(); //send stop bit
send_lcd_char(message);
return 1;
// INTCON=255;
}
send_lcd_char_const(const char message[]) // this one send string to LCD
{
int i=0;
Soft_I2C_Start (); //send start bit
Soft_I2C_Write(0x42); //LCD address
Soft_I2C_Write(2); //write to I2c
//start string
while (message){ // write all string to LCD
Soft_I2C_Write(message[i++]);
}
Soft_I2C_Stop(); //send stop bit
return 1;
}
send_lcd_char(char message[]) // this one send string to LCD this one for variables chars
{
int i=0;
Soft_I2C_Start (); //send start bit
Soft_I2C_Write(0x42); //LCD address
Soft_I2C_Write(2); //write to I2c
//start string
while (message){ // write all string to LCD
Soft_I2C_Write(message[i++]);
}
Soft_I2C_Stop(); //send stop bit
return 1;
}
send_lcd_clear() // clear and home
{
Soft_I2C_Start (); //send start bit
Soft_I2C_Write(0x42); //LCD address
Soft_I2C_Write(1); //write to I2c
Soft_I2C_Write(1); //write to I2c
Soft_I2C_Stop(); //send stop bit
return 1;
}
light_lcd(char lit)
{
Soft_I2C_Start (); //send start bit
Soft_I2C_Write(0x42); //LCD address
Soft_I2C_Write(3); //write to I2c
if (lit==1) // light off
Soft_I2C_Write(1); //write to I2c
else // light on
Soft_I2C_Write(0); //write to I2c
Soft_I2C_Stop(); //send stop bit
return 1;
}
lcd_line2()
{ //command A8 from http://www.doc.ic.ac.uk/~ih/doc/lcd/instruct.html
Soft_I2C_Start (); //send start bit
Soft_I2C_Write(0x42); //LCD address
Soft_I2C_Write(0x1); //Command
Soft_I2C_Write(0xc0);
Soft_I2C_Stop(); //send stop bit
return 1;
}
// #endif
Thanks,
Roee.
Just a general recommendation (and no offense intended - this is meant in a constructive way and applies to many other postings as well):
When you want to maximize the chance that somebody actually looks at your code (or even tries to run and debug it), keep the code short; i.e. strip it down to minimum size that just shows the problem (but still compiles), and remove all other pieces.
Few people will bother with ten pages of code and the question "this does not work - can you fix it for me" (often not even telling WHAT does not work). Many more will do this when the code segment is 10 lines. Especially if you also add extensive description of what the code is intended to do, what does not work, what you have already tried in order to make it working, and so on.
Wolfgang
When you want to maximize the chance that somebody actually looks at your code (or even tries to run and debug it), keep the code short; i.e. strip it down to minimum size that just shows the problem (but still compiles), and remove all other pieces.
Few people will bother with ten pages of code and the question "this does not work - can you fix it for me" (often not even telling WHAT does not work). Many more will do this when the code segment is 10 lines. Especially if you also add extensive description of what the code is intended to do, what does not work, what you have already tried in order to make it working, and so on.
Wolfgang
-
- Posts: 9
- Joined: 05 Apr 2009 04:22
- Location: Sumaré, Brazil
I2C for 16F73
Please help me.
I don´t have the codes for I2c communication to PIC 16F73.
Any peaple can help me?
Tanks
My email is clubinho.x.x@gmail.com
I don´t have the codes for I2c communication to PIC 16F73.
Any peaple can help me?
Tanks
My email is clubinho.x.x@gmail.com
Not sure where the problem lies (btw, here we go again - if you expect help, please provide SUFFICIENT information about what exactly you want to do, and what does not work. Most peoples mind reading skills are limited.)
The PIC16F73 is supported by MicroC, so just use the library hardware I2C or software I2C routines. Refer to the help file for commands and for sample code.
The PIC16F73 is supported by MicroC, so just use the library hardware I2C or software I2C routines. Refer to the help file for commands and for sample code.
-
- Posts: 9
- Joined: 05 Apr 2009 04:22
- Location: Sumaré, Brazil
I don´t found the I2C suport in the MikroC.
My MikroC is:
mikroC, mikroElektronika C compiler
for Microchip PIC microcontrollers
Version: 8.2.0.0
I have the I2C suport only the 18F452.
Do you can send me your version the MikroC?
tanks,
clubinho.x.x@gmail.com
My MikroC is:
mikroC, mikroElektronika C compiler
for Microchip PIC microcontrollers
Version: 8.2.0.0
I have the I2C suport only the 18F452.
Do you can send me your version the MikroC?
tanks,
clubinho.x.x@gmail.com
You should be able to use the same library functions. The MikroC distribution contains sample code for a limited number of different devices, but you can use the same for other devices as well (sometimes changes to certain register initialization will be necessary though). Don't forget to select the correct device in the development environment (combobox on the left side). But the library function are usable across devices, so just look up the I2C examples or the software I2C examples for e.g. the PIC16F887 and us that as your starting point . It's really just a few lines of code.
Sending you "my" version on MikroC wouldn't be very useful, since you can just download the installer from the MikroE website; I do not have any "secret" or "special" version of that software.
Wolfgang
Sending you "my" version on MikroC wouldn't be very useful, since you can just download the installer from the MikroE website; I do not have any "secret" or "special" version of that software.
Wolfgang
-
- Posts: 9
- Joined: 05 Apr 2009 04:22
- Location: Sumaré, Brazil
-
- Posts: 9
- Joined: 05 Apr 2009 04:22
- Location: Sumaré, Brazil