Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC Slave is not always listening

Status
Not open for further replies.

SneaKSz

Member
Hello all,

I have a strange problem with sending data from: Laptop->RS232->Master PIC-> I2C-> Slave PIC-> SPI->DAC.


I turn on the supply's for the master and slave and then send data from the laptop to master to the slave. The data send from the laptop to the master is sent back to check if its proper. That's the case , but the slave doesn"t always send data to the DAC.

When I switch off and than on the supplys for both PIC's ( master & slaves) a few times and send data the DAC receives his data.

I don't know what the problem can be, its like the slave is still resetted when the master sends its data. I see the I2C pulses coming on the pins of the slave.

The wires are all proper soldered, its just a problem with the voltage of the slave.
I think its hardware related but can't find the problem. The reset pins of both pics are connected with a 10K resistor to Vdd and both oscillators work.

Someone has an idea for this problem?

Kind regards
 
Not knowing what you have coded up etc, my suggestion would be to try sending an i2c & spi start/ stop condition as part of your initialisation routines on the PIC's. If it were likely to be a power issue, I would suggest an econo reset device rather than just a resistor in the MCLR pins.

rgds
 
I dont think it"s software, I"ll turn on the supply for the slave reset the µC and then send data. Maybe that will help.

Thanks for the econo reset device.

If someone has other inputs , please tell them!

Kind regards
 
Depending on how fast the devices start up the slave can get out of sync. What I do is, when initializing the master, check the data line and if it's high send clock pulses until it's clear.

Mike.
 
Thanks for the advice Pommie.

But you say you send clock pulses, do you write data to SSPBUF so you have your data on the SDA and clockpulses appear on SCL?
Start - Data to SSPBUF - Stop?

But the SDA is pulled high with a resistor, it's normal that SDA is high

The data shouldnt be the same as the address of the slave !

Kind regards
 
Last edited:
Sorry, got my logic levels mixed up, if it's low then clock it until it's high. I clock it in software before initialising the hardware module.

Mike.
 
I have a similar set up, but I use serial RS232 throughout.. The master was transmitting far to fast and the slave didn't respond. I put a 400ms delay on the master to let the slave time to be ready. It seemed to work.. When the I2C bus is being initialized there may be a collision!!

Cheers Ian
 
Thanks for your suggestion Ian! I"ll keep the delay in mind.

Also thanks for your suggestion Pommie, can I use your software I2C loop please?

Cheers SneakSz
 
I've used a line from master to slaves' reset. Master releases slave, waits for comm line state as ready signal, then sends & waits for reply (ack). Ensures slave sync at cost of free running independent tasks. My use: download new op data to slave, while master manages RF data link.
Can also use line to hit interrupt that sets a flag, then wait for max latency of flag (or signal/state) to start comm routine. I haven't done this one.
Multiple micros seems difficult, but can solve realtime conflicts when multiple interrupts aren't good enough. Good Hunting... <<<)))
 
Last edited:
Hi guys , ive noticed something. When I get a connection with the slave and it reads my data. I can send every kind of data that I want. But when I dont have a connection with the slave and I send data, it doesnt listen. Even when I change the data.

My point is that when I have a connection with the slave, it functions all well. So could it be that my PIC gets stucked somewhere?

My " loop" is this :
Code:
void Mode(){
// mode
//
//0 : Resistance
//1 : Voltage
//2 : Current
	while(1){
			Delay10TCYx(100);
			if ( Modeselect==1){ // if new data is entered.
			Delay10TCYx(10);
			
					switch(mode){
						case 0:	 Delay10TCYx(10);
								 
								 Resistance(); // mode
							break;
						case 1:  Voltage();
							break;
						case 2:  Current();
							break;
					}
			}	
	}	
}

from the main I call Mode() and when I get data from the master over I2C, after the interrupt modeselect becomes = 1 and I enter the if ( Modeselect==1). Dependant on the value of mode i switch to the case. After the method I return to the while.

Now before the master is sending data, modeselect = 0 , and it keeps jumping in the while.

Could this give make my program getting stucked?

EDIT : with settings some output high , I know that the program jumps to the case, but doesnt jump to the method
 
Last edited:
I found the problem: the counter that helds the count for the times the received loop was entered, was not initialised with 0 and just a random value. That's why sometimes the Slave listened.

Kind regards
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top