khanh my
Junior Member level 2
- Joined
- Mar 19, 2013
- Messages
- 23
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,412
#include <16f887.h>
#fuses hs,nolvp,nowdt
#use delay(clock=20000000)
#include <lcd_lib_4bit.c>
#use i2c(master,sda=pin_c4,scl=pin_c3 )
#define slave_add 0x10
#define slave_add2 0x40
unsigned int doc,doc2;
void hienthi_lcd(void);
unsigned int read_slave(void);
unsigned int read_slave2(void);
void main() {
set_tris_d(0x00);
lcd_init();
while(true){
doc=read_slave();
doc2=read_slave2();
hienthi_lcd();
}
}
unsigned int read_slave(void) {
unsigned int dulieu;
i2c_start(1);
i2c_write(0x10);
dulieu=i2c_read();
i2c_stop();
return dulieu;
}
unsigned int read_slave2(void) {
unsigned int dulieu2;
i2c_start(1);
i2c_write(0x40);
dulieu2=i2c_read();
i2c_stop();
return dulieu2;
}
void hienthi_lcd() {
lcd_putcmd(line_1);
lcd_putchar("MASTER");
lcd_putcmd(line_2);
printf(lcd_putchar,"H0=%3u H1=%3u",doc,doc2);
}
#include <16f887.h>
#fuses hs,nolvp,nowdt
#device adc=10
#use delay(clock=20000000)
#use i2c(slave,sda=pin_c4,scl=pin_c3,address=0x10)
#include <lcd_lib_4bit.c>
float doc;
unsigned int16 a;
void doc_adc(void);
void xuly_adc(void);
void hienthi_lcd(void);
#int_ssp
void ssp_interupt () {
if(i2c_isr_state()==0x80) {
i2c_write((unsigned int)doc);
}
}
void main (void) {
set_tris_a(0xff);
set_tris_d(0x00);
lcd_init();
setup_adc_ports(san0);
setup_adc(adc_clock_internal);
enable_interrupts(int_ssp);
clear_interrupt(int_ssp);
enable_interrupts(global);
while (true) {
doc_adc();
xuly_adc();
hienthi_lcd ();
}
}
void doc_adc () {
set_adc_channel(0);
delay_us(10);
a=read_adc ();
}
void xuly_adc () {
doc=((float)a*4.88)/10;
}
void hienthi_lcd () {
lcd_putcmd(line_1);
lcd_putchar("SLAVE 1");
lcd_putcmd(line_2);
printf(lcd_putchar,"H0=%3.0f",doc);
}
#include <16f887.h>
#fuses hs,nolvp,nowdt
#device adc=10
#use delay(clock=20000000)
#use i2c(slave,sda=pin_c4,scl=pin_c3,address=0x40)
#include <lcd_lib_4bit.c>
float doc2;
unsigned int16 a2;
void doc_adc(void);
void xuly_adc(void);
void hienthi_lcd(void);
#int_ssp
void ssp_interupt () {
if(i2c_isr_state()==0x80) {
i2c_write((unsigned int)doc2);
}
}
void main (void) {
set_tris_a(0xff);
set_tris_d(0x00);
lcd_init();
setup_adc_ports(san0);
setup_adc(adc_clock_internal);
enable_interrupts(int_ssp);
clear_interrupt(int_ssp);
enable_interrupts(global);
while (true) {
doc_adc();
xuly_adc();
hienthi_lcd ();
}
}
void doc_adc () {
set_adc_channel(0);
delay_us(10);
a2=read_adc ();
}
void xuly_adc () {
doc2=((float)a2*4.88)/10;
}
void hienthi_lcd () {
lcd_putcmd(line_1);
lcd_putchar("SLAVE 2");
lcd_putcmd(line_2);
printf(lcd_putchar,"H1=%3.0f",doc2);
}
Hi! arunsharma0731Check Slave 2 individually.
And see if it is working or not.
It will be better if you tell us what slave devices you are using.
Could you check the mistake for me?Check Slave 2 individually.
And see if it is working or not.
It will be better if you tell us what slave devices you are using.
How are you enabling Slaves. Only one slave can use I2C bus at a time. Post your circuit.
You can only select one device at a time for I2C Communication.
@spudboy488:The first byte sent by the master after a start condition is the address byte. All slaves listen to the address and only the slave that has the matching address will send and ACK. The other slaves ignore all bus traffic until the bus goes to a stop condition. Then they all wait for a start condition again. At least that is the way it is supposed to work.
you can tell the device here? I've tried jayanth.devarayanadurga but failedThere may be some additional setup required for the slave PIC16F887 parts
you can download my file and fix the error help me?Where is the device address for the slaves set in this project. The slaves are PIC MCUs. Do PIC MCU comes with different addresses?
Read page 185 and 186 of datasheet. You have to use SS pin to select slave i.e., You have to make SS pin of slave high. Remove one slave and use just one slave and see if I2C is working between master and one slave. You are writing some slave address from master i.e., 0x10 and 0x40. Where did you get those values from?
url]http://www.mikroe.com/forum/viewtopic.php?t=8106&highlight=i2c+slave[/url]
http://www.mikroe.com/forum/viewtopic.php?t=20543
CCS C code
**broken link removed**
Hope these helps. Try with one master and one slave. See if it works.
Hello,
I' using CCS C example of code for I2C communication between one Master and one Slave. It's work well.
However, i'm trying now with two Slaves, One Master and i have problem. 2 slave data transmission on the master was wrong (LCD of Master 255)
code master
tried but notuse set_tris_c(0x18); in the slaves.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?