I2c tutorial, or maybe h files

Status
Not open for further replies.

Dr_Doggy

Well-Known Member
as i am learning the micros and the protocols such as 232, spi,pwm,irda, and now i2c, i have been using my own code instead of the h libraries. and now with my circuits i am using proper pins, so that if i ever update code i can switch to hardware code

maybe we(I) should take the time to learn the basics of how these h files work, i am just wondering when i start with a h file how do i find it features and how to implement them.?

for example alot of the time it is the config bits, which i need, in wat order, i find that in general when i look at libraries, i find the instructions(subroutines) that they hold. but i find it is usually vague on how to use it. suggestions? how do you guys approach a new library when you encounter them?

i tried several of the online examples, but using i2c.h seems to get stuck in a loop when writing the register byte.
my more immediate problem today though is that i have written my own i2c code to interface with this array, which is now returning bytes:
https://www.robot-electronics.co.uk/htm/tpa81tech.htm
i am able to get the acknowledgements from the array, at the proper address and in general am getting good responses, except every second byte or so is responding as 119-123, when it should only be showing 23-25, but then not after that,even happening when i hit the same register over and over. it is the same when i keep repeating firmware requests on a repeat of 10 requests this is what responds: 7,103,7,99,7,95,7,95,7,95.

the switch seems to help, i have now gotten a few more registers to respond properly:
245,69,24,26,26,25,22,25,24,22 registers 2-8 seem to be working, but register 9 never changes, register 1 should be 20-30,as the internal temp, and i doubt register 0 value is software version 245


while(1) {

while (address == 0){address = i2c_lookup();}


cnt4 = 0;
for(cnt3=0; cnt3<10;cnt3++){
switch (cnt3){
case 5: data[cnt4] = i2c_read(address, cnt3);cnt4++;break;
case 7: data[cnt4] = i2c_read(address, cnt3);cnt4++;break;

default:
data[cnt4] = i2c_read(address, cnt3);
data[cnt4] = i2c_read(address, cnt3);cnt4++;break;

}
}
xxx = 1;



LCD(254);LCD(81);LCD(32);LCD(32);
LCD5(data[2]);LCD(32);LCD5(data[3]);LCD(32);LCD5(data[4]);LCD(32);LCD5(data[5]);
LCD(254);LCD(69);LCD(41);
LCD5(data[6]);LCD(32);LCD5(data[7]);LCD(32);LCD5(data[8]);LCD(32);LCD5(data[9]);
Delay10KTCYx(240);
Delay10KTCYx(10);
}

any ideas?
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…