payam
Joined: 15 Nov 2005 Posts: 42
|
Posted: Tue Jun 12, 2007 9:58 pm Post subject: AVR-SPI |
|
|
Hi.
I have a problem about the connection of SPI between three Micro.
Please help me.
One of these three micro is Master and the others are Slave.
Would you please tell me How should I transfer the information from slaves to master?
In aditional, the micro that I use, is ATMega8.
There are the program of each micro here.
*********Master Program*********
$regfile = "m8def.dat"
$crystal = 8000000
Config Pind.5 = 0
Config Pind.6 = 0
Config Pind.7 = 0
Config Pinb.0 = 0
Config Pinb.2 = 1
Config Pinb.3 = 0
Config Pinb.4 = 1
Config Pinb.5 = 0
Config Lcd = 20 * 4
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , _
Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
Config Spi = Hard , Interrupt = Off , Data Order = Lsb , Master = Yes , _
Polarity = High , Phase = 0 , Clockrate = 64 , Noss = 1
Set Portd.5
Set Portd.6
Dim A As Byte
Dim B As Byte
Dim C As Byte
Spiinit
A = 1 : B = 2
Display Off
Do
Debounce Pind.7 , 1 , Slave1
Debounce Pinb.0 , 1 , Slave2
Loop
End
Slave1:
Display On
Cls
Locate 2 , 6
Lcd "a="
Reset Portd.5
Spiout A , 1
Waitms 5
Spiin C , 1
Set Portd.5
Lcd C : Wait 2
Return
Slave2:
Cls
Display On
Locate 2 , 6
Lcd "b="
Reset Portd.6
Spiout B , 1
Waitms 5
Spiin C , 1
Set Portd.6
Lcd Spdr : Wait 2
Return
**********Slave1 Program*********
$regfile = "m8def.dat"
$crystal = 8000000
Config Spi = Hard , Interrupt = On , Data Order = Lsb , Master = No , _
Polarity = High , Phase = 0 , Clockrate = 64
Enable Interrupts
Enable Spi
On Spi Slave1
Dim A As Byte
Spiinit
A = 0
Do
Wait 1
A = A + 1
Loop
End 'end program
Slave1:
Disable Interrupts
If Spdr = 1 Then
Spiout A , 1
End If
Enable Interrupts
Return
*********Slave2 Program*********
$regfile = "m8def.dat"
$crystal = 8000000
Config Spi = Hard , Interrupt = On , Data Order = Lsb , Master = No , _
Polarity = High , Phase = 0 , Clockrate = 64
Enable Interrupts
Enable Spi
On Spi Slave2
Dim B As Byte
Spiinit
B = 0
Do
Wait 2
B = B + 1
Loop
End 'end program
Slave2:
Disable Interrupts
If Spdr = 2 Then
Spiout B , 1
Waitms 20
End If
Enable Interrupts
Return
******************
software: BASCOM 1.11.7.4 |
|