Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20709

BASCOM-AVR : SPI slave IRQ doesn't work : NEWTOPIC

$
0
0
Hello everybody, I want to connect 2 atMega168 using SPI. I've connected GND and PB3..5 pins (MOSI/MOSI/SCK) directly (no cross over!). I took the sample code for the slave, but the slave will never receive any data. The ISR is never triggered. Anybody help, please? Thanks Ralph Code for the master: [code:1:317568b295] $regfile = "M168DEF.DAT" ' atMEGA168 $crystal = 8000000 ' 8 MHz Takt Config Portb.3 = Output ' MOSI Config Portb.4 = Input ' MISO Config Portb.5 = Output ' SCK (8MHz / 128 = 62.5kHz) Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 128 , Noss = 1 Spiinit Dim A(1) As Byte A(1) = 42 Do Wait 1 Spiout A(1) , 1 Loop End [/code:1:317568b295] Code for the slave: [code:1:317568b295] $regfile = "M168DEF.DAT" ' atMEGA168 $crystal = 8000000 ' 8 MHz Takt $baud = 115200 Config Pinb.3 = Input ' MOSI Config Pinb.4 = Output ' MISO Config Pinb.5 = Input ' SCK Config Spi = Hard , Interrupt = On , Data Order = Msb , Master = No , Polarity = Low , Phase = 0 , Clockrate = 128 Spiinit On Spi Spi_isr Nosave ' specify the SPI interrupt Enable Spi ' enable spi interrupt Enable Interrupts ' enable global interrupts Dim B As Byte , Rbit As Bit , Bsend As Byte Print "start" ' show that we started Spdr = 0 ' start with sending 0 the first time Do If Rbit = 1 Then ' when data received Print B ' print it Reset Rbit ' wait for more data Bsend = Bsend + 1 Spdr = Bsend ' increase SPDR End If Loop ' Interrupt routine Spi_isr: push r24 ' save used register in r24, sreg ' save SREG push r24 B = Spdr ' Load data Set Rbit ' we received something pop r24 !out sreg, r24 ' restore SREG pop r24 ' and the used register Return [/code:1:317568b295] [code:1:317568b295][/code:1:317568b295] [b:317568b295][color=red:317568b295](BASCOM-AVR version : 2.0.7.7 )[/b:317568b295][/color:317568b295]

Viewing all articles
Browse latest Browse all 20709

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>