View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
help me on my first program with SPI |
Posted: Wed Oct 07, 2009 4:02 pm |
|
|
Hi
I like start my study on SPI communication, but I don’t understand some questions.
For example,
Is possible I transmit a string between two PICs?
Someone can explain me how I can make this “simple” example.
On PIC master I have two switches connected on PIN_C0 and PIN_C1, and on slave PIC I have one led on PIN_B7. I like if I press PIN_C0 led turn-on, if I press PIN_C1 led turn-off.
But I like witch when I press PIN_C0 write slave PIC an string “ON” if a press PIN_C1 write on slave PIC a string “OFF”, and after read by slave it make operation.
If is possible help me make this little program for I can start used this protocol…
PS: I used PIC18F252
Best regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Wed Oct 07, 2009 6:34 pm |
|
|
Hi
thanks PCM Programmer, in your 1ª link in slave PIC, if I choose on Master charter 'A' (read ADC) it wait for adc result from slave PIC, correct? but where slave PIC stay write to master?
I don't understand this.... slave PIC don't need some like spi_write()?
best regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 07, 2009 7:15 pm |
|
|
The slave is writing directly to the SPI buffer register. Example:
Code: | SSPBUF = adc_result; |
|
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Thu Oct 08, 2009 5:32 am |
|
|
Hi
In "#byte SSPBUF = 0x13"? How I know register on 18F252?
But master go there read? Slave don't need send information to master?
best regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 08, 2009 12:57 pm |
|
|
Quote: | How I know register on 18F252? |
Download the 18F252 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39564c.pdf
Find the SSPBUF address in this section:
Quote: | TABLE 4-1: SPECIAL FUNCTION REGISTER MAP |
Quote: | Slave don't need send information to master? |
It does. The slave puts the data into SSPBUF. Then the master
reads the data from the slave with this line:
Code: | result = spi_read(0); |
|
|
|
|