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

BASCOM-AVR : XMEGA SPI MASTER SLAVE : NEWTOPIC

$
0
0
Hi! I have connected two Xmega32a4 via SPI. And it does work just fine with sample code as below. But the comunication only goes from master to slave. Now I would like to be able to send some bytes from slave to master. But I really have no clue, where to start. I'm really looking foreward for Your help. [b:1a7d89b88b]MASTER code:[/b:1a7d89b88b] [code:1:1a7d89b88b]Dim Select_bit As Bit Dim Start_of_frame As Byte Dim Array(10) As Byte Reset Select_bit 'We start with 0 Start_of_frame = 111 Array(1) = 1 'CONFIG SPI MASTER on Port c Config Spic = Hard , Master = Yes , Mode = 0 , Clockdiv = Clk32 , Data_order = Msb , Ss = None Open "SPIC" For Binary As #10 do Incr Array(1) 'SEND 1 BYTE ARRAY TO SLAVE Reset Cs1 'Select Slave Print #10 , Start_of_frame ; Array(1) , 1 'SEND Start Byte then ARRAY WITH 1 BYTES Set Cs1 'Deselect Slave Print #8 , Array(1) ' Print B to Serial PC connection Lcdat 8 , 1 , Array(1) wait 1 loop[/code:1:1a7d89b88b] [b:1a7d89b88b]SLAVE code:[/b:1a7d89b88b] [code:1:1a7d89b88b]Dim Spi_data(5) As Byte Dim Spi_data_ready As Bit ' CONFIG SPI SLAVE on Port C ' Clock comes from SPI Master (Maximum clock rate a XMEGA Slave can handle is when MASTER Clockrate is CLK4) Config Spic = Hard , Master = No , Mode = 0 , Data_order = Msb 'XMEGA SPI SLAVE Open "SPIC" For Binary As #10 On Spic_int Spi_data_available Enable Spic_int , Lo do If Spi_data_ready = 1 Then Reset Spi_data_ready Print #1 , "Received Array = " ; spi_data(1) Lcdat 8 , 1 , Spi_data(1) Lcdat 8 , 30 , Spi_data(2) endif waitms 100[/code:1:1a7d89b88b] 'SPI Port C Interrupt Service Routine Spi_data_available: Incr I Spi_data(i) = Spic_data 'Read the SPI Data Register If I = 2 Then I = 0 Set Spi_data_ready End If Return Best regards Andrej [b:1a7d89b88b][color=red:1a7d89b88b](BASCOM-AVR version : 2.0.7.6 )[/b:1a7d89b88b][/color:1a7d89b88b]

Viewing all articles
Browse latest Browse all 20562

Trending Articles



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