|
|
View previous topic :: View next topic |
Author |
Message |
andibaciu
Joined: 06 Feb 2006 Posts: 6
|
I2C Master/Slave Multibytes PROBLEM |
Posted: Thu Mar 23, 2006 11:30 am |
|
|
I have a little project with an I2C communication Master/Slave with 2 16F877 (master - slave). My problem show up when with master i try to read the Slave after i allready send data to slave. When the Master send data to Slave all data are received ok by the Slave. When the Master try to read this data from the Slave some problems apear. This problems are only for data with value between 64 and 191 (there are no problems with data between 0 - 63 or between 192 - 255). My observation is data between 0 - 63 have bit 6 and bit 7 - 00xxxxxx ; data between 191 - 255 have bit 6 and bit 7 - 11xxxxxx, and data between 64 - 191 have bit 6 and bit 7 - 01xxxxxx or 10xxxxxx.
I use PCWH Compiler V3.245 and for simulation i use Proteus 6.7 SP3 (the hardware interface was made and the problem sill exist - so ... Proteus simulator is ok).
Code for Master is:
Code: |
#include <16F877.h>
#define FREQUENCY 20000000
#define I2C_SDA PIN_C4
#define I2C_SCL PIN_C3
#define SLAVE_ADDR 0x40 // Even number, address to be sent to slave pic,
// must match. Note read address is slave address + 1.
#fuses HS,NOWDT,PROTECT,NOLVP,NOPUT,BROWNOUT
#use delay(clock=FREQUENCY)
#use fast_io(C)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#use i2c(master, sda=I2C_SDA, scl=I2C_SCL, FORCE_HW, SLOW)
#include <math.h>
byte com,calculeaza;
char x[12];
short int status=0;
void trimite_primeste_I2C(unsigned int8 comanda, unsigned int8 valoare1, unsigned int8 valoare2, unsigned int8 valoare3, unsigned int8 valoare4);
void primeste_I2C();
#int_rda
void rda()
{
x[0]=getc();
delay_us(10);
if(x[0]=='x')
{
com=1;
disable_interrupts(INT_RDA);
calculeaza=0;
}
}
void inttobin (int intval)
{
short int x0,x1,x2,x3,x4,x5,x6,x7;
byte byteval;
byteval=intval;
x0=bit_test(byteval,0);
x1=bit_test(byteval,1);
x2=bit_test(byteval,2);
x3=bit_test(byteval,3);
x4=bit_test(byteval,4);
x5=bit_test(byteval,5);
x6=bit_test(byteval,6);
x7=bit_test(byteval,7);
printf("\n\rValoare= %u --> Binar: %u%u%u%u%u%u%u%u",intval,x7,x6,x5,x4,x3,x2,x1,x0);
}
void main()
{
set_tris_c(0b11011000);
calculeaza=0;
com=0;
printf("\n\rStart...");
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
//Se verifica daca exista modulul de relee de frecventa atasat
i2c_start();
status=i2c_write(SLAVE_ADDR);
i2c_stop();
if(status==1)
printf("\n\rModulul Relee de Frecventa - OFF.");
if(status==0)
printf("\n\rModulul Relee de Frecventa - ON.");
delay_ms(100);
if(status==0)
{
trimite_primeste_i2c(127,128,129,130,131);
//trimite_primeste_I2C(64,65,128,129,255);
//primeste_i2c();
}
while(TRUE)
{
///////////////////////////////////////////////////////////////////////
//modulul de verificare a transmisiei de date prin RS232
///////////////////////////////////////////////////////////////////////
if(com==1)
{
printf("Comunicatie ON.");
while(com==1)
{
gets(x);
delay_us(10);
if(x[0]=='s' && x[1]=='t' && x[2]=='o' && x[3]=='p')
{
printf("Comunicatie OFF.");
enable_interrupts(INT_RDA);
}
if(x[0]=='s' && x[1]=='t' && x[2]=='a' && x[3]=='r' && x[4]=='t')
{
trimite_primeste_I2C(254,64,127,128,255);
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//modulul de calculare a turatiei in functie de timpul unei ture (numarul de dinti ai unei ture)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(calculeaza==1)
{
calculeaza=0;
}
}
}
void trimite_primeste_I2C(unsigned int8 comanda, unsigned int8 valoare1, unsigned int8 valoare2, unsigned int8 valoare3, unsigned int8 valoare4)
{
unsigned int8 rxbuf[5]; // Buffer for data received back from the slave pic
int8 i=0;
// Clear the Master receive buffer
for(i=0;i<5;i++)
rxbuf[i] = 0;
inttobin(comanda);
inttobin(valoare1);
inttobin(valoare2);
inttobin(valoare3);
inttobin(valoare4);
// Send some numbers to the slave pic buffer. Slave clears it's buffer
// each time round when address match occurs.
// Small delays are to allow time for slave to get to and from
// interrupt handler.
i2c_start();
i2c_write(SLAVE_ADDR); // Must match address of slave pic
delay_us(10);
i2c_write(comanda); //Trimite comanda
delay_us(10);
i2c_write(valoare1);
delay_us(10);
i2c_write(valoare2);
delay_us(10);
i2c_write(valoare3);
delay_us(10);
i2c_write(valoare4);
delay_us(10); //i2c_stop();
//delay_ms(5);
// Now read back the numbers without releasing i2c bus,
// could do a STOP here and a new START.
i2c_start(); // A restart
i2c_write(SLAVE_ADDR + 1); // Slave read address
for(i=0; i<4; i++)
{
//output_high(I2C_SDA);
//output_low(I2C_SCL);
rxbuf[i] = i2c_read(); // Note that Slave may be delaying response
// by holding SCL low. i2c_read() monitors
// SCL and takes care of this.
}
rxbuf[4] = i2c_read(0); // Last one nack (high), resets slave i2c
// logic. Very important, i2c bus will hang
// otherwise.
i2c_stop(); // Release the i2c bus
for(i=0; i<=4; i++)
{
inttobin(rxbuf[i]);
}
}
void primeste_I2C()
{
unsigned int8 rxbuf[5]; // Buffer for data received back from the slave pic
int8 i=0;
// Clear the Master receive buffer
for(i=0;i<5;i++)
rxbuf[i] = 0;
// Now read back the numbers without releasing i2c bus,
// could do a STOP here and a new START.
i2c_start(); // A restart
i2c_write(SLAVE_ADDR + 1); // Slave read address
for(i=0; i<4; i++)
{
//output_high(I2C_SDA);
//output_low(I2C_SCL);
rxbuf[i] = i2c_read(); // Note that Slave may be delaying response
// by holding SCL low. i2c_read() monitors
// SCL and takes care of this.
}
rxbuf[4] = i2c_read(0); // Last one nack (high), resets slave i2c
// logic. Very important, i2c bus will hang
// otherwise.
i2c_stop(); // Release the i2c bus
for(i=0; i<=4; i++)
{
inttobin(rxbuf[i]);
}
}
|
Code for Slave is:
Code: |
#include <16F877.h>
#define FREQUENCY 20010000
#define I2C_SDA PIN_C4
#define I2C_SCL PIN_C3
#define SLAVE_ADDR 0x40 // Even number, address to be sent to slave pic,
// must match. Note read address is slave address + 1.
#fuses HS,WDT,PROTECT,NOLVP,NOPUT,BROWNOUT
#use delay(clock=FREQUENCY)
#use fast_io(c)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#use i2c(slave, sda=I2C_SDA, scl=I2C_SCL,address=SLAVE_ADDR, FORCE_HW, SLOW)
#include <math.h>
// Registers and bits associated with i2c Sync Serial Port
#byte SSPADD = 0x93 // Slave address held here
#byte SSPCON1= 0x14 // SSP control reg 1
#byte SSPBUF = 0x13 // Buffer for SSP data
#byte SSPSTAT= 0x94 // SSP status reg
// SSPSTAT bits
#bit BF = SSPSTAT.0 // Buffer full status bit. Read-only bit.
// Receive mode 1 = SSPBUF full.
// Tx mode 1 = data transmit in progress, SSPBUF full.
// 0 = complete, SSPBUF empty.
// (does not include ack and stop bits in either case)
#bit UA = SSPSTAT.1 // User needs to update addr. in SSPADD, 10 bit mode only.
#bit R_W = SSPSTAT.2 // Holds read/write status from last address match, valid
// to next start,stop, or not /ack bit.
// Slave mode 1 = read, Master mode transmit in progress.
#bit START=SSPSTAT.3 // Start bit (S) has been detected last
#bit STOP= SSPSTAT.4 // Stop bit (P) has been detected last
#bit D_A = SSPSTAT.5 // Data/addr bit. 1 = last byte received or transmitted
// was data.
#bit CKE = SSPSTAT.6 // 0 = input levels are i2c specs, 1 = SMB specs.
#bit SMP = SSPSTAT.7 // Slew rate control. 1 = disabled for 100kHz or 1MHz modes
// SSPCON bits Slave mode 7 bits
#bit SSPM0 = SSPCON1.0 // SSP mode bits 0
#bit SSPM1 = SSPCON1.1 // " 1
#bit SSPM2 = SSPCON1.2 // " 1
#bit SSPM3 = SSPCON1.3 // " 0
#bit CKP = SSPCON1.4 // Clock, 1 = enable clock, 0 = clock stretch
#bit SSPEN = SSPCON1.5 // SSP enable bit
#bit SSPOV = SSPCON1.6 // Receive overflow indicator bit. In receive mode, a
// byte is received while the SSPBUF is holding
// previous byte. Must clear in software.
#bit WCOL = SSPCON1.7 // Write collision detect bit. In slave mode, 1 means
// SSBUF written while transmitting previous word.
// Must clear in software.
#byte TRISC = 0x87
#byte PIR1 = 0x0c
#bit SSPIF = PIR1.3 // SSP interrupt flag bit
#define BUF_LEN 5
unsigned int8 buf[BUF_LEN]; // Buffer for data to be received or transmitted
unsigned int8 buf2; // Buffer for data to be received or transmitted
int8 buf_index;
// Possible i2c states, SSPSTAT for the four relevant bits
#define STATE1 0x09 // D/A=0,S=1,R/W=0,BF=1. Master tx, slave addr
#define STATE2 0x29 // D/A=1,S=1,R/W=0,BF=1. Master tx, data
#define STATE3 0x0C // D/A=0,S=1,R/W=1,BF=0. Master rx, slave addr+1
#define STATE4 0x2C // D/A=1,S=1,R/W=1,BF=0. Master rx, data with ack
#define STATE5 0x28 // D/A=1,S=1,R/W=0,BF=0. Master rx, data with nack (high)
#define STATE6 0x30 // D/A=1
char x[16];
short int tempverifica=0;
short int com, calculeaza;
void Comunicatie();
void inttobin (int intval);
#int_rda
void rda()
{
x[0]=getc();
delay_us(10);
if(x[0]=='z')
{
com=1;
disable_interrupts(INT_RDA);
calculeaza=0;
}
}
// i2c interrupt handler
#int_SSP
void SSP_isr()
{
int8 state=0,incoming=0,TEMPSSPSTAT=0;
// Loop while flag set
while(SSPIF==1)
{
TEMPSSPSTAT=SSPSTAT;
//state=i2c_isr_state();
// Keep only bits D/A, S, R/W, BF
switch (TEMPSSPSTAT & 0x2d)
{
case(STATE1):
// Master write operation, address byte in SSPBUF.
// Clear the data buffer. Keep Master waiting by clock stretching
// for this to finish before it sends data byte(s). Otherwise
// SSPBUF will be full and an acknowledge will not be generated
// by the slave i2c hardware.
CKP = 0; // Hold SCL low
for (buf_index = 0; buf_index < BUF_LEN; buf_index++)
{
buf[buf_index] = 0;
}
buf_index = 0; // Reset the data buffer index
buf[buf_index] = SSPBUF; // Dummy read to clear BF (read only bit)
//buf[buf_index] = i2c_read();
SSPOV = 0; // Clear receive overflow flag, could be set from last
// time because after nack, SSPBUF was still full.
CKP = 1; // Allow master to continue by re-enabling SCL
break;
case(STATE2):
// Master write operation, data byte in SSPBUF
// If previous byte in SSPBUF not read, NACK sent back to master
// Get data byte, also clears BF
CKP = 0; // Make Master wait by holding SCL low
buf[buf_index] = SSPBUF; // Move received byte to array
//buf[buf_index] = i2c_read();
SSPOV = 0; // Same comment as for State1
buf_index++;
if (buf_index >= BUF_LEN) buf_index = 0; // Wrap around
CKP = 1; // Allow master to continue by re-enabling SCL
break;
case(STATE3):
// Master has begun new read operation by initiating a START or RESTART
// then sending Slave address (read) byte, now in SSPBUF.
// Looks like clock enable bit CKP cleared on interrupt, so must
// set it again to allow Master to clock data byte out.
CKP = 0; // Make Master wait by holding SCL low
////////////////////////////////////////
// Aici poti sa verifici ce ai primit //
////////////////////////////////////////
for (buf_index = 0; buf_index < BUF_LEN; buf_index++)
{
inttobin(buf[buf_index]);
}
buf_index = 0; // Reset buffer index
while(BF)
{
//Asteapta ca BF sa fie 0
}
do
{
WCOL=0;
//i2c_write(buf[buf_index]);
SSPBUF = buf[buf_index];// Load 1st byte from data buffer
}
while(WCOL);
buf_index++;
CKP = 1; // Enable SCL for Master to shift byte out
break;
case(STATE4):
// Master read operation, last byte was data, SSPBUF empty.
// Move next byte to SSPBUF and SSPSR.
// Same comment for CKP bit as in STATE3.
CKP = 0; // Make Master wait by holding SCL low
while(BF)
{
//Asteapta ca BF sa fie 0
}
do
{
WCOL=0;
//i2c_write(buf[buf_index]);
SSPBUF = buf[buf_index];// Get next byte from data buffer
}
while(WCOL);
buf_index++;
if (buf_index >= BUF_LEN) buf_index = 0; // Wrap around
CKP = 1; // Enable SCL for Master to shift byte out
break;
case(STATE5):
// A nack (high) was received from Master in response to data
// byte received from Slave (last byte). Slave i2c logic is reset,
// and waits for next Master operation.
SSPEN=0;
SSPEN=1;
break;
default:
// Error, trap here. Watchdog will reset pic (must be enabled, and
// watchdog timer cleared in other loops).
printf("\n\rEroare: 0x%X",SSPSTAT);
while(1);
break;
}
/* if (state == 0x80)
{
////////////////////////////////////////
// Aici poti sa verifici ce ai primit //
////////////////////////////////////////
for (buf_index = 0; buf_index < BUF_LEN; buf_index++)
{
inttobin(buf[buf_index]);
}
buf_index = 0; // Reset buffer index
printf("\n\r Trimit: %X",buf[buf_index]);
while(BF)
{
//Asteapta ca BF sa fie 0
}
do
{
WCOL=0;
i2c_write(buf[buf_index]);
//SSPBUF = buf[buf_index];// Get next byte from data buffer
}
while(WCOL);
buf_index++;
CKP=1;
}
if (state > 0x80)
{
printf("\n\r Trimit: %X",buf[buf_index]);
while(BF)
{
//Asteapta ca BF sa fie 0
}
do
{
WCOL=0;
i2c_write(buf[buf_index]);
//SSPBUF = buf[buf_index];// Get next byte from data buffer
}
while(WCOL);
buf_index++;
CKP=1;
}
*/ SSPIF = 0;
}
}
void Comunicatie()
{
printf("Comunicatie ON.");
while(com==1)
{
gets(x);
delay_us(10);
if(x[0]=='s' && x[1]=='t' && x[2]=='o' && x[3]=='p')
{
printf("Comunicatie OFF.");
delay_ms(500);
printf("Resetare PIC.");
delay_ms(500);
reset_cpu();
}
}
}
void inttobin (int intval)
{
short int x0,x1,x2,x3,x4,x5,x6,x7;
byte byteval;
byteval=intval;
x0=bit_test(byteval,0);
x1=bit_test(byteval,1);
x2=bit_test(byteval,2);
x3=bit_test(byteval,3);
x4=bit_test(byteval,4);
x5=bit_test(byteval,5);
x6=bit_test(byteval,6);
x7=bit_test(byteval,7);
printf("\n\rValoare= %u --> Binar: %u%u%u%u%u%u%u%u",intval,x7,x6,x5,x4,x3,x2,x1,x0);
}
void main()
{
setup_wdt(WDT_2304MS);
//set_tris_c(0b11011000);
output_float(I2C_SDA);
output_float(I2C_SCL);
//initializare variabile
com=0;
calculeaza=0;
enable_interrupts(INT_SSP);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(TRUE)
{
if(tempverifica==1)
{
tempverifica=0;
for (buf_index = 0; buf_index < BUF_LEN; buf_index++)
{
inttobin(buf[buf_index]);
}
buf_index = 0;
}
if(com==1)
{
Comunicatie();
}
if(calculeaza==1)
{
}
restart_wdt();
}
}
|
This data are an example for what i say:
Master send:
Code: |
Valoare= 63 --> Binar: 00111111
Valoare= 73 --> Binar: 01001001
Valoare= 133 --> Binar: 10000101
Valoare= 193 --> Binar: 11000001
Valoare= 200 --> Binar: 11001000
|
Slave receive:
Code: |
Valoare= 63 --> Binar: 00111111
Valoare= 73 --> Binar: 01001001
Valoare= 133 --> Binar: 10000101
Valoare= 193 --> Binar: 11000001
Valoare= 200 --> Binar: 11001000
|
Master receive:
Code: |
Valoare= 63 --> Binar: 00111111
Valoare= 201 --> Binar: 11001001
Valoare= 5 --> Binar: 00000101
Valoare= 193 --> Binar: 11000001
Valoare= 200 --> Binar: 11001000
|
Anybody know how to resolve this problem ???
Any help is wait and appreciate!!!
Thanks! (and scuse me for my bad english). |
|
|
andibaciu
Joined: 06 Feb 2006 Posts: 6
|
|
Posted: Tue Mar 28, 2006 3:08 am |
|
|
Any ideea ??? i sill have this problem .....
Or maybe somebody have a good and working I2C MULTIBYTE SLAVE rutine .... and want to help some peoples ....
Thanks in advance!!! |
|
|
Storic
Joined: 03 Dec 2005 Posts: 182 Location: Australia SA
|
|
Posted: Tue Mar 28, 2006 5:38 am |
|
|
I dont know if this will help, I remember reading a post not that long ago where incorrect data was being sent, this was because there was old data that was not flushed out.
This was fixed by zeroing the data before new data is added. I could not find this post to give you the link.
Andrew _________________ What has been learnt if you make the same mistake? |
|
|
Guest
|
|
Posted: Tue Mar 28, 2006 7:24 am |
|
|
I'd say, stick a delay in here:
Code: |
i2c_write(SLAVE_ADDR + 1); // Slave read address
for(i=0; i<4; i++)
{
//output_high(I2C_SDA);
//output_low(I2C_SCL);
rxbuf[i] = i2c_read(); // Note that Slave may be delaying response
|
If you think about it, the slave, has to get into it's routine, to 'see' that a read address has been sent, and write it's response to the buffer, _before_ the master starts clocking data back. The interrupt doesn't trigger, till the write completes, and it takes about 30 instruction times to arrive in the 'handler' code. There are then perhaps another 15 instruction times, before the slave code decides this is a read, and transfers the data. At 20MHz, you are talking probably about 10uSec, before the data will be ready for the master to retrieve.
Now, the slave writes it's byte (let's guess), after the first bit has already been clocked out. This will cause the WCOL flag to be set in the slave (which is then cleared), and the top bit of the returned data, will be what was in the shift register already (actually the top bit of the transmitted command). Since this is '0', this is why values with this bit set fail. I must admit, I'd have actually expected the rest of the byte to perhaps be shifted left by one bit, but this would depend on how the shift register is actually implemented in the PIC.
The fact that the second bit may also be affected, suggests fractionally more than 10uSec delay may be needed (given that the default I2C rate, is 10uSec/bit).
Best Wishes |
|
|
andibaciu
Joined: 06 Feb 2006 Posts: 6
|
|
Posted: Tue Mar 28, 2006 9:46 am |
|
|
Thanks you for your answers .... apreciate ...
I fix my problem ... the entire code is ok but the simulator Proteus 6.7 sp3 is the problem ... this simulator work ok with any device with i2c from his library but not work with pic in slave mode ... my problem it's now solved. I make this circuit on a test board and all my soft work ok ... master send data to slave ok and master read this data from slave ok ....
So ... for other peoples who use this simulator it's better to know this problem.
Thanks people!!! |
|
|
apes Guest
|
|
Posted: Mon Apr 03, 2006 9:30 am |
|
|
HI,
I was just wondering how do you actually see what bits the Slave is getting. I mean do you have an LCD hooked up or does your compiler show that info.
Do you send data from PC or the Master is pre programmed?
I have not done any complex programming so its taking me too much time to undersatnd the code. (I am not really good at C either) |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Apr 03, 2006 10:24 am |
|
|
Quote: |
I was just wondering how do you actually see what bits the Slave is getting. I mean do you have an LCD hooked up or does your compiler show that info. |
Its up to you- ICD, ICE, printf, LCD, etc...
Quote: |
Do you send data from PC or the Master is pre programmed?
|
Are you asking how to program a PIC? Certainly, not through I2C unless you wrote your own bootloader that uses I2C!
Quote: |
I have not done any complex programming so its taking me too much time to undersatnd the code. (I am not really good at C either) |
Probably a school assignment. If that is the case, then you should have started earlier and/or paid more attention in class. |
|
|
apes Guest
|
School proj |
Posted: Mon Apr 03, 2006 3:18 pm |
|
|
Hi Mark,
Well its school project and there is no help from anyone as its a senior design capstone project. Plus all the group memeberes are EE majors and we all took C and C++ way back in sophomore year which is like more than 2 yrs ago.
Proj is about sending data and power down the same line ( 22 gauge single pair copper wire) and wire is 3000 ft long. So tons of interference, to prevent all the noise affecting the data we modulate it using FSK powerline tranceiver and then couple it with the power signal and send it to other end. the data is sent through PC ( VB script) and the power source is a 24 V DC battery.
To prove that there is error free data going down the other end we have a array of light bulbs ( 8 bulbs )which we control using a PIC.Certain bulbs go on/off corresponding to certain data. PIC 16F874 cannot supply enough power to bulbs as they r rated at 30 V DC so the power bus and the PIC togather with help of power MOSfet control the bulbs. This is all we need to do and we have done that and we have spare time. The communication parts works for 3000 ft which was our goal.
Offcourse the project sponser said that since there r stability issues with the PC he would wants to replace the PC with a master PIC. And the actual system that he would use would have more than 1 pic based device at the receiving end. So I have been looking into Pic to PIc comm specifically 1 master with several slave devices. I seen examples like Ex_pbusm and dallas 1 wire and loads of other stuff.
The hardest part for me is understanding the code |
|
|
apes Guest
|
issues |
Posted: Mon Apr 03, 2006 3:39 pm |
|
|
Oh so i was tellin I use MPLAB and CCS compiler and to upload hex file to PIC we use ICD and so far to verify that certain data is getting to other end we use LEDs so if wanto send byte 'm' to receving pic then the receving pic would output high pin c0 for example if the received byte was m. But so far I was just sending receving 1 byte at a time so it was easy. this was all PC to PIC.
For master PIC to multiple slave pic communication (using 1 wire system) i need atleast sending 5 bytes ( or 8 bytes if if wanto include payload) 1st one being target address 2nd being senders address and 3rd byte being opcode which should turn on/off certain LED and last being checksum. There are lots of similar codes but its my problem I am having hard time uderstanding it since my entire group is sort of programming illiterate and I was dumb enough to take on the programming responsibility . I kiinda feel like a kindergarden kid who happily volunteered for performing a nuerosurgery on someone and then later reliased hmm bad move. And thats my story MARk so before u tell me I should pay more attention in class you should have atleast asked me what difficulties I have.
If you think my questions are extremly dumb please ignore them.
Thanks
Apu |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Apr 03, 2006 7:57 pm |
|
|
Only 2 years and you have forgot what you learned! Let's see, 21 years for me. Good thing I didn't forget it. My employer wouldn't be too happy. Aren't we suppose to learn stuff in school? By learn, I mean learn and retain!
As for your problem, I wouldn't use I2C. It really wasn't meant for any great distances. We've used it for probably 8 years or more communicating between micros in a lighting control panel. You should instead look at something like CAN or RS485. For your project, I would recommend RS485 with 9 bit addressing. |
|
|
Apes Guest
|
|
Posted: Tue Apr 04, 2006 3:13 pm |
|
|
HI Mark,
Well the data is being modulated with a FSK signal ( which is then coupled with the power signal) so its not just data. We have an error detection/ correction chip and atleast under LAB conditions we were able to transmitt 100% error free data so I'm not too bothered about reliable data transmission.
Thanks for the advice though. I appretiate it. I had looked into RS 485 too and the 2wire app note on RS 485 and If i remmeber it correctly it was only for sending data and no power ( well the device being controlled at other end requires 5 amps current. ) so we had ruled out RS485
But anyways we have reliable communication taking place so thats not the problem.
My problem is understanding how to program PIC to use registers or EEPROM and stuff like that. Thats the kind of stuff we did not learn in the programming classes. Thats for me to figure out and which I am trying to eventhough its highly frustrating but its fun to some level. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Apr 04, 2006 6:27 pm |
|
|
I don't think you explained your project very well.
Quote: |
Offcourse the project sponser said that since there r stability issues with the PC he would wants to replace the PC with a master PIC. And the actual system that he would use would have more than 1 pic based device at the receiving end. So I have been looking into Pic to PIc comm specifically 1 master with several slave devices. I seen examples like Ex_pbusm and dallas 1 wire and loads of other stuff.
The hardest part for me is understanding the code
|
My RS485 suggestion was about this. Currently you are using RS232? Correct? Is power being transmitted from the PC side? |
|
|
Guest
|
|
Posted: Tue Apr 04, 2006 9:58 pm |
|
|
[/img]http://pg.photos.yahoo.com/ph/apoood/detail?.dir=/1196&.dnm=42af.jpg&.src=ph[/img] |
|
|
apes Guest
|
|
|
|
|
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
|