Hallo erstmal,
Ich möchte 2 mc miteinander verbinden via spi. Hab das vorher noch nicht gemacht. Jetzt habe ich mir ersteinmal die bespielcodes von Bascom angeschaut und leicht verändert. An meinem Slave hängt ein LCD dran (funtioniert auch). Wenn ich allerdings vorgenden Code auf dem mc laufen lasse, zeigt mir das lcd nur "kästen" an. Es bekommt vom Master noch keine Daten, meines erachtens sollte es aber dann auch garnichts anzeigen und nicht "kästen". Jetzt hab ich im Code von Bascom was gelesen: "' Tested on the STK500. The STK200 will NOT work.
' Use the STK500 or another circuit"
Was soll ich den darunter verstehen???? Was hat denn das Programmiergerät mit der Funktion vom SPI bzw in diesem fall ersteinmal vom LCD zu tun???Code:'------------------------------------------------------------------ ' SPI-SLAVE.BAS ' (c) MCS Electronics ' sample shows how to create a SPI SLAVE ' use together with sendspi.bas '------------------------------------------------------------------ ' Tested on the STK500. The STK200 will NOT work. ' Use the STK500 or another circuit $regfile = "m32def.dat" $framesize = 32 $swstack = 32 $hwstack = 32 $crystal = 4000000 Dim B As Byte , Rbit As Bit , Bsend As Byte 'First configure the MISO pin Config Pinb.6 = Output ' MISO Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portb.5 , Rs = Portb.4 Config Lcd = 16 * 2 'Then configure the SPI hardware SPCR register Config Spi = Hard , Interrupt = On , Data Order = Msb , Master = No , Polarity = Low , Phase = 0 , Clockrate = 128 'Then init the SPI pins directly after the CONFIG SPI statement. Spiinit 'specify the SPI interrupt On Spi Spi_isr Nosave 'enable global interrupts Enable Interrupts 'show that we started Cursor Off Noblink Cls Spdr = 0 ' start with sending 0 the first time Do If Rbit = 1 Then Locate 1 , 1 Lcd "empfangen : " ; B Reset Rbit Bsend = Bsend + 1 : Spdr = Bsend 'increase SPDR End If ' your code goes here Loop 'Interrupt routine 'since we used NOSAVE, we must save and restore the registers ourself 'when this ISR is called it will send the content from SPDR to the master 'the first time this is 0 Spi_isr: push r24 '; save used register in r24,sreg '; save sreg push r24 B = Spdr Set Rbit ' we received something pop r24 !out sreg,r24 '; restore sreg pop r24 '; and the used register Return







Zitieren

Lesezeichen