View previous topic :: View next topic |
Author |
Message |
falleaf
Joined: 23 May 2004 Posts: 48
|
Need I2C examples |
Posted: Tue Jun 08, 2004 10:14 am |
|
|
Anyone have a I2C slave code, and master code pls send to me
[email protected]
Thanks indeed. |
|
|
William H. Conley III
Joined: 27 May 2004 Posts: 17 Location: Tucson, AZ
|
|
Posted: Tue Jun 08, 2004 1:04 pm |
|
|
Good Luck.................... |
|
|
falleaf
Joined: 23 May 2004 Posts: 48
|
|
Posted: Tue Jun 08, 2004 9:41 pm |
|
|
Receive nothing! ??
pls try with [email protected]
thanks muchie |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Jun 08, 2004 9:46 pm |
|
|
You can also try looking at the driver files in the \drivers directory as many of them use I2C. |
|
|
Guest
|
|
Posted: Wed Jun 09, 2004 1:42 am |
|
|
Browse the forum |
|
|
falleaf
Joined: 23 May 2004 Posts: 48
|
|
Posted: Wed Jun 09, 2004 7:09 am |
|
|
You don't understand my requirement that
1) I know the examples in CCS C. However, it's very simple, and I'm new in C. I would like to have full examples of slave and master so that I may understand more clearly about how CCS C work. Because I used to use MPASM.
2) I don't want to browse the forum, because the forum posted some wrong codes and needed to fix. I would like the good examples that someone of you did. Anything, any purposes. I can understand C, and used MPASM, but I would like to understand C for PIC MORE CLEARLY.
3) Thanks indeed for your help. This is my seriosly urgent project, and I need further help. Thanks again for all. |
|
|
Radix Guest
|
|
Posted: Wed Jun 09, 2004 7:21 am |
|
|
Can you tell us more about the project you are working on?
Regards |
|
|
falleaf
Joined: 23 May 2004 Posts: 48
|
|
Posted: Wed Jun 09, 2004 10:03 am |
|
|
Oh, I only would like to send 8 byte from master to slave, and read the slave buffer of 8 byte. And I need an example code.
I may read I2C in ASM, but I'm learning CCS C. Therefore, an example will help meeh muchie.
The master will send 8 byte to slave when I press a button, and the slave save it to given memories. Each 10ms, the master will read 8 other bytes (other given memory) from the slave.
It's oki in ASM for me, but I don't know anything about C for PIC. That is my problem.
I read some function of CCS C, but I cannot imagine how it work. And if you have an example, pls send it to meeh asap.
Thanks indeed for all. |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Wed Jun 09, 2004 11:30 am |
|
|
If you have been using ASM you should be able to quickly read the listing file generated with those basic I2C examples that are included with the compiler. The listing shows the assembly instruction associated with each line of code written in C. This is helpfull when your unsure if your syntax is correct. Coming from assembly this should help you a lot. |
|
|
jds-pic
Joined: 17 Sep 2003 Posts: 205
|
|
Posted: Wed Jun 09, 2004 8:39 pm |
|
|
falleaf wrote: | Oh, I only would like to send 8 byte from master to slave, and read the slave buffer of 8 byte. And I need an example code.
The master will send 8 byte to slave when I press a button, and the slave save it to given memories. Each 10ms, the master will read 8 other bytes (other given memory) from the slave.
|
if you look at the examples in the CCS manual, and also the source in the code library forum, this is trivial to implement.
Quote: |
It's oki in ASM for me, but I don't know anything about C for PIC. That is my problem.
I read some function of CCS C, but I cannot imagine how it work. |
perhaps compile the code and inspect the output assembly?
Quote: |
And if you have an example, pls send it to meeh asap.
|
we see you are in a hurry. don't be in such a hurry not to learn. if you don't understand what is going on in the C source, it will make debugging difficult if not impossible. ergo, it will not be possible for you to just grab someone's code and plug it in. instead, read and understand the examples in the CCS examples, and in the code library. then get out the datasheet for the memory device you are using and get to work.
jds-pic |
|
|
falleaf
Joined: 23 May 2004 Posts: 48
|
|
Posted: Thu Jun 10, 2004 1:05 am |
|
|
Quote: | perhaps compile the code and inspect the output assembly? |
The problem is that I would like to learn C. I'm not professional, but quite good in ASM. I would like to compare them, understand more clearly about C for PIC.
Thanks indeed.
I cannot find the similar project at code library thread in this forum? Which forum did you mean? |
|
|
falleaf
Joined: 23 May 2004 Posts: 48
|
|
Posted: Thu Jun 10, 2004 1:49 am |
|
|
You all seem to lost me. Everything I need is that would you send me whatever you did with I2C to communicate 2 PICs.
The manual is similar to the Help files, nothing different. And I have all the examples in CCS C standard. But the example of slave I2C only is not enough for me.
Compile to ASM and read the code is wier !!! I cannot do it, because they write in direct addresses code. I need to read some C code, I may help me to understand clearly.
So, pls send me if you have, or give me the direct link.
I helped many people to repair their codes in ASM, and I think no problems if I ask for an example code in C? There are many library in ASM but it's difficult for me to find the C libraries.
Thanks muchies. |
|
|
falleaf
Joined: 23 May 2004 Posts: 48
|
|
Posted: Thu Jun 10, 2004 1:51 am |
|
|
You all seem to lost me. Everything I need is that would you send me whatever you did with I2C to communicate 2 PICs.
The manual is similar to the Help files, nothing different. And I have all the examples in CCS C standard. But the example of slave I2C only is not enough for me.
Compile to ASM and read the code is wier !!! I cannot do it, because they write in direct addresses code. I need to read some C code, I may help me to understand clearly.
So, pls send me if you have, or give me the direct link.
I helped many people to repair their codes in ASM, and I think no problems if I ask for an example code in C? There are many library in ASM but it's difficult for me to find the C libraries.
Thanks muchies. |
|
|
CHRIS Guest
|
I2C SOURCE |
Posted: Thu Jun 10, 2004 5:17 am |
|
|
I wrote this code for write and read in a extern EEPROM by I2C.
I hope that it serves to you.
#define EEPROM_SCL PIN_C3
#define EEPROM_SDA PIN_C4
#define EEPROM_SIZE 32768 // 256kb = 32 Kb * 8
#define eeprom_address 0xa0 // 0xa0 => A1=0, A0=0 //se le suma 1 cuando para lectura
#use delay(clock=20000000)
#use i2c(Master,Fast,sda=EEPROM_SDA,scl=EEPROM_SCL)
void init_ext_eeprom() {
output_float(eeprom_scl);
output_float(eeprom_sda);
}
void write_ext_eeprom(long addr,byte data) {
i2c_start();
i2c_write(eeprom_address); //bits de la direccion de dispositivo : 1 0 1 0 0 A1 A0 R/W
i2c_write(addr); //OJO!!! R/W => R=1, W=0
i2c_write(addr>>8); //parte alta de addr
i2c_write(data);
i2c_stop();
delay_ms(11);
}
byte read_ext_eeprom(long addr) {
byte data;
i2c_start();
i2c_write(eeprom_address); //bits de la direccion de dispositivo : 1 0 1 0 0 A1 A0 R/W
i2c_write(addr); //OJO!!! R/W => R=1, W=0
i2c_write(addr>>8); //parte alta de addr
i2c_start();
i2c_write(eeprom_address+1); //bits de la direccion de dispositivo : 1 0 1 0 0 A1 A0 R/W
data=i2c_read(0); //El argumento indica que no requiere ACK
i2c_stop();
return(data);
} |
|
|
jds-pic
Joined: 17 Sep 2003 Posts: 205
|
|
Posted: Thu Jun 10, 2004 8:46 am |
|
|
[quote="falleaf"] Quote: | The problem is that I would like to learn C. |
you can not learn C by looking at an i2c driver.
first, purchase the book "The C Programming Language" by Kernighan and Ritchie. you can get it online for about US$30. this is *the* book when it comes to learning practical C. amazingly, it is not a thick, unwieldy text.
next, write a hello world program in C for your PIC.
then, write a program that stores and retrieves values from a generic i2c EEPROM. this will give you a foundation for the "master-slave" nature of i2c communications.
finally, you can move on to having two pics talk over i2c, with one acting as the master and the other as the slave.
if you are trying to skip directly to the last step, i think you will have a frustrating road. if it's any consolation, i made the same mistake when i learned java -- especially with java's native handling of error conditions. i was in too much of a hurry to bother with learning the fundamentals of throwing/catching exceptions; subsequently, i became increasingly frustrated until i went back and really dug into how it all worked.
all that said, why don't you just connect the your pics with two wires and speak TTL-level serial at 19,200bps between them? debugging is trivial compared to master/slave i2c, and you just need to learn the printf() and getc() functions.
jds-pic |
|
|
|