CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

I2C simple test program

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Hector
Guest







I2C simple test program
PostPosted: Fri May 09, 2003 3:29 am     Reply with quote

Hey everybody!
I'm trying to make a simple test for communicate two 18F452 via I2C, I'll prefer to use the build-in function to make it more readable. In this code, the slave non-stop showing what it gets, but actually it's nothing! Which is the problem?

//I2C communication between PICs
//MASTER
//PIC 1

#include <18F452.h>
#device *=16

//#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT
#use DELAY(CLOCK=19660800)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)

#BYTE PORTC = 0xF82
#BYTE PORTB = 0xF81
#BYTE PORTA = 0xF80

#define SLAVE_ADDRESS 0xA0

#use rs232(baud=9600, BITS=8, PARITY=N, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use I2C (MASTER, SDA=PIN_C4, SCL=PIN_C3)




void main(void)
{

delay_ms(2000);
SET_TRIS_A(0x01);
SET_TRIS_B(0x00);
SET_TRIS_C(0x88);

output_float(PIN_C3);
output_float(PIN_C4);

while(TRUE)
{
i2c_start();
i2c_write(SLAVE_ADDRESS); //write
i2c_write('H');
i2c_stop();

delay_ms(1000);

}
}

__________________________________
//I2C communication between PICs
//SLAVE
//PIC 2

#include <18F452.h>
#device *=16

//#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT
#use DELAY(CLOCK=19660800)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)

#BYTE PORTC = 0xF82
#BYTE PORTB = 0xF81
#BYTE PORTA = 0xF80

#define SLAVE_ADDRESS 0xA0

#use rs232(baud=9600, BITS=8, PARITY=N, xmit=PIN_A1, rcv=PIN_A0,ERRORS)
#use I2C (SLAVE, SDA = PIN_C4, SCL = PIN_C3, address = SLAVE_ADDRESS)


void main()
{
int c=0;

delay_ms(2000);
SET_TRIS_A(0x01); // 0000 0001
SET_TRIS_B(0x00); // 0000 0000
SET_TRIS_C(0x88); // 1000 1000
output_float(PIN_C3);
output_float(PIN_C4);


printf("I'm your slave, tell what you want\n\r");
while(TRUE)
{
while(!i2c_poll())
c=i2c_read(0);
printf("What I get: \%c\n\r", c);

}
}

any help will be usefull
thank you
___________________________
This message was ported from CCS's old forum
Original Post ID: 14281
John H.
Guest







Are the output_float commands compiling properly?
PostPosted: Fri May 09, 2003 8:21 am     Reply with quote

Hi Hector,

I'm here searching the forum for answers to the same question. I've got an I2C routine that I wrote that runs properly on an older version of the compiler and now isn't working properly.

Check the *.LST output from the compiler and see if it compiled the "output_float" commands. I suspect that there is an issue when using fast_io and the output_float commands. In my listing, the output_float appear to have been ignored by the compiler without any warning or error message.

You might be able to get your routine up and running if you switch over to standard_io. That seems to allow the output_float command to work.

I'm still looking for a workaround. I prefer not to use the supplied I2C routines.

Let me know if your listing file shows the same.

JH



:=Hey everybody!
:=I'm trying to make a simple test for communicate two 18F452 via I2C, I'll prefer to use the build-in function to make it more readable. In this code, the slave non-stop showing what it gets, but actually it's nothing! Which is the problem?
:=
:=//I2C communication between PICs
:=//MASTER
:=//PIC 1
:=
:=#include <18F452.h>
:=#device *=16
:=
:=//#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT
:=#use DELAY(CLOCK=19660800)
:=#use fast_io(A)
:=#use fast_io(B)
:=#use fast_io(C)
:=
:=#BYTE PORTC = 0xF82
:=#BYTE PORTB = 0xF81
:=#BYTE PORTA = 0xF80
:=
:=#define SLAVE_ADDRESS 0xA0
:=
:=#use rs232(baud=9600, BITS=8, PARITY=N, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
:=#use I2C (MASTER, SDA=PIN_C4, SCL=PIN_C3)
:=
:=
:=
:=
:=void main(void)
:={
:=
:=delay_ms(2000);
:= SET_TRIS_A(0x01);
:= SET_TRIS_B(0x00);
:= SET_TRIS_C(0x88);
:=
:= output_float(PIN_C3);
:= output_float(PIN_C4);
:=
:=while(TRUE)
:={
:= i2c_start();
:= i2c_write(SLAVE_ADDRESS); //write
:= i2c_write('H');
:= i2c_stop();
:=
:= delay_ms(1000);
:=
:=}
:=}
:=
:=__________________________________
:=//I2C communication between PICs
:=//SLAVE
:=//PIC 2
:=
:=#include <18F452.h>
:=#device *=16
:=
:=//#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT
:=#use DELAY(CLOCK=19660800)
:=#use fast_io(A)
:=#use fast_io(B)
:=#use fast_io(C)
:=
:=#BYTE PORTC = 0xF82
:=#BYTE PORTB = 0xF81
:=#BYTE PORTA = 0xF80
:=
:=#define SLAVE_ADDRESS 0xA0
:=
:=#use rs232(baud=9600, BITS=8, PARITY=N, xmit=PIN_A1, rcv=PIN_A0,ERRORS)
:=#use I2C (SLAVE, SDA = PIN_C4, SCL = PIN_C3, address = SLAVE_ADDRESS)
:=
:=
:=void main()
:={
:= int c=0;
:=
:= delay_ms(2000);
:= SET_TRIS_A(0x01); // 0000 0001
:= SET_TRIS_B(0x00); // 0000 0000
:= SET_TRIS_C(0x88); // 1000 1000
:= output_float(PIN_C3);
:= output_float(PIN_C4);
:=
:=
:= printf("I'm your slave, tell what you want\n\r");
:= while(TRUE)
:= {
:= while(!i2c_poll())
:= c=i2c_read(0);
:= printf("What I get: \%c\n\r", c);
:=
:= }
:=}
:=
:=any help will be usefull
:=thank you
___________________________
This message was ported from CCS's old forum
Original Post ID: 14293
John H.
Guest







Are the output_float commands compiling properly?
PostPosted: Fri May 09, 2003 8:27 am     Reply with quote

Hi Hector,

I'm here searching the forum for answers to the same question. I've got an I2C routine that I wrote that runs properly on an older version of the compiler and now isn't working properly.

Check the *.LST output from the compiler and see if it compiled the "output_float" commands. I suspect that there is an issue when using fast_io and the output_float commands. In my listing, the output_float appear to have been ignored by the compiler without any warning or error message.

You might be able to get your routine up and running if you switch over to standard_io. That seems to allow the output_float command to work.

I'm still looking for a workaround. I prefer not to use the supplied I2C routines.

Let me know if your listing file shows the same.

JH



:=Hey everybody!
:=I'm trying to make a simple test for communicate two 18F452 via I2C, I'll prefer to use the build-in function to make it more readable. In this code, the slave non-stop showing what it gets, but actually it's nothing! Which is the problem?
:=
:=//I2C communication between PICs
:=//MASTER
:=//PIC 1
:=
:=#include <18F452.h>
:=#device *=16
:=
:=//#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT
:=#use DELAY(CLOCK=19660800)
:=#use fast_io(A)
:=#use fast_io(B)
:=#use fast_io(C)
:=
:=#BYTE PORTC = 0xF82
:=#BYTE PORTB = 0xF81
:=#BYTE PORTA = 0xF80
:=
:=#define SLAVE_ADDRESS 0xA0
:=
:=#use rs232(baud=9600, BITS=8, PARITY=N, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
:=#use I2C (MASTER, SDA=PIN_C4, SCL=PIN_C3)
:=
:=
:=
:=
:=void main(void)
:={
:=
:=delay_ms(2000);
:= SET_TRIS_A(0x01);
:= SET_TRIS_B(0x00);
:= SET_TRIS_C(0x88);
:=
:= output_float(PIN_C3);
:= output_float(PIN_C4);
:=
:=while(TRUE)
:={
:= i2c_start();
:= i2c_write(SLAVE_ADDRESS); //write
:= i2c_write('H');
:= i2c_stop();
:=
:= delay_ms(1000);
:=
:=}
:=}
:=
:=__________________________________
:=//I2C communication between PICs
:=//SLAVE
:=//PIC 2
:=
:=#include <18F452.h>
:=#device *=16
:=
:=//#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT
:=#use DELAY(CLOCK=19660800)
:=#use fast_io(A)
:=#use fast_io(B)
:=#use fast_io(C)
:=
:=#BYTE PORTC = 0xF82
:=#BYTE PORTB = 0xF81
:=#BYTE PORTA = 0xF80
:=
:=#define SLAVE_ADDRESS 0xA0
:=
:=#use rs232(baud=9600, BITS=8, PARITY=N, xmit=PIN_A1, rcv=PIN_A0,ERRORS)
:=#use I2C (SLAVE, SDA = PIN_C4, SCL = PIN_C3, address = SLAVE_ADDRESS)
:=
:=
:=void main()
:={
:= int c=0;
:=
:= delay_ms(2000);
:= SET_TRIS_A(0x01); // 0000 0001
:= SET_TRIS_B(0x00); // 0000 0000
:= SET_TRIS_C(0x88); // 1000 1000
:= output_float(PIN_C3);
:= output_float(PIN_C4);
:=
:=
:= printf("I'm your slave, tell what you want\n\r");
:= while(TRUE)
:= {
:= while(!i2c_poll())
:= c=i2c_read(0);
:= printf("What I get: \%c\n\r", c);
:=
:= }
:=}
:=
:=any help will be usefull
:=thank you
___________________________
This message was ported from CCS's old forum
Original Post ID: 14295
Hector
Guest







Re: Are the output_float commands compiling properly?
PostPosted: Sat May 10, 2003 9:13 am     Reply with quote

hey John!

you're right, the compiler ignores the output_float senteces when using #use fast_io. But that's why you can do it by you own, just set in the TRIS register the pins as input and you'll have the same effect.
Another cuestion does anybody knows if the i2c_poll runs correctly in the slave?

Hector



:=Hi Hector,
:=
:=I'm here searching the forum for answers to the same question. I've got an I2C routine that I wrote that runs properly on an older version of the compiler and now isn't working properly.
:=
:=Check the *.LST output from the compiler and see if it compiled the "output_float" commands. I suspect that there is an issue when using fast_io and the output_float commands. In my listing, the output_float appear to have been ignored by the compiler without any warning or error message.
:=
:=You might be able to get your routine up and running if you switch over to standard_io. That seems to allow the output_float command to work.
:=
:=I'm still looking for a workaround. I prefer not to use the supplied I2C routines.
:=
:=Let me know if your listing file shows the same.
:=
:=JH
___________________________
This message was ported from CCS's old forum
Original Post ID: 14338
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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