I am trying to make PIC1 be a master and PIC2 be a slave through SPI communication. I want to send a command from PIC1 (master) to PIC2 (slave), then have it do something. However I want to establish another SPI communication from PIC2 (slave) to a digital potentiometer (MCP4241) through SPI communication as well. Will this work ?
To illustrate :
PIC1 sends 'a' ---- > PIC2 reads it
PIC2 ---- > establishes connection with digital pot(MCP4241)
PIC2 ---- > sends data to digital pot
So there will be SPI communications between PIC1 and PIC2, then PIC2 and digital pot, I just don't know if this is going to work since I would need to use the same pins. For the two PICs, I am using pic16f690.
I hope my question is clear and please if this won't work how should I fix it?
Thanks!
First of all, for an easy life, I'd recommend using a PIC with 2 SPI ports for PIC2.
However, if you are sure you want to use just one SPI port to be a master sometimes and a slave then the thing to keep in mind is that you really don't want both PICs to try to drive the serial line at the same time. You may have to write the TRIS registers to make the port tristate go high-z as well as disabling the spi peripheral.
If you put some series resistors in then things will be less bad if e.g. pic1 tries to drive SCLK high while pic2 is trying to drive it low then the current flowing from pic1 to pic2 will be limited
You could use an extra GPIO to allow pic2 to tell pic1 when it is busy. You need to have a clear idea of the flow of execution between the 2 devices so that you don't get caught with race conditions etc
for example you could have a flow of
There are loads of ways to implement something like this. The important thing is to know clearly what the flow is going to be before you start implementation