Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Send SPI command to CC1101

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
pinkfloyd11

Bascom Member



Joined: 02 Jul 2007
Posts: 248

italy.gif
PostPosted: Wed Mar 11, 2015 4:31 pm    Post subject: Send SPI command to CC1101 Reply with quote

Hello

I have problem on while(miso)
Read seem to work also without while(miso)
Write don't work again....


'////////////////////////////////////////////
' SPI SEND and RECEIVE COMMAND
'////////////////////////////////////////////

'*********************************
'Direttive al compilatore
'*********************************
$Regfile="m48pdef.dat"
$Crystal=4000000
$hwstack=40
$swstack=16
$framesize=32
'*********************************
$Include "CC1101 REGISTER.inc"

CONFIG Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 16, NOSS = 0
SPIINIT

DECLARE SUB CONFRONTA_DUE_LETTURE()
DECLARE SUB SCRIVI_LEGGI_E_CONFRONTA()


LED_ROSSO Alias PortD.3
CONFIG LED_ROSSO = Output

LED_VERDE Alias PortC.2
CONFIG LED_VERDE = Output


CHIP_SELECT Alias Portb.2
CONFIG CHIP_SELECT = Output

Dim Reg_Part_Number as Byte
Dim Reg_Curr_Version as Byte
Dim Reg_Sync_W as Byte
Dim Reg_Sync_R as Byte

Dim Byte_Ricevuto_1 as Byte
Dim Byte_Ricevuto_2 as Byte

Dim Valore_Scritto as Byte
Dim Valore_Letto as Byte
Dim S As String * 8

'Dal Datasheet table 43
'0x04 SYNC1 Sync word, high byte
'[7] := Header --> 1
'[6] := Burst --> 0
'[5-0] := Indirizzo Registro --> 0x00 --> 000100
'[Byte completo] = 00000100
S = "00000100"
Reg_Sync_W = binval (S)


'Dal Datasheet table 43
'0x04 SYNC1 Sync word, high byte
'[7] := Header --> 1
'[6] := Burst --> 0
'[5-0] := Indirizzo Registro --> 0x00 --> 000100
'[Byte completo] = 00000100
S = "10000100"
Reg_Sync_R = binval (S)

'Dal Datasheet table 44:
'0x30 (0xF0) PARTNUM Part number
'[7] := Header --> 1
'[6] := Burst --> 0
'[5-0] := Indirizzo Registro --> 0x30 --> 110000
'[Byte completo] = 10110000
S = "10110000"
Reg_Part_Number = binval (S)

'0x31 (0xF1) VERSION Current version number
'[7] := Header --> 1
'[6] := Burst --> 0
'[5-0] := Indirizzo Registro --> 0x30 --> 110001
'[Byte completo] = 10110001
S = "10110001"
Reg_Curr_Version = binval (S)

DO


'CALL CONFRONTA_DUE_LETTURE
CALL SCRIVI_LEGGI_E_CONFRONTA


Wait 1

LOOP

'_______________________________________________________________________________________

SUB CONFRONTA_DUE_LETTURE()

Byte_Ricevuto_1 = 11
Byte_Ricevuto_2 = 22


'READ 1
SET LED_ROSSO
RESET CHIP_SELECT
SPIout Reg_Part_Number, 1
SPIin Byte_Ricevuto_1, 1
SET CHIP_SELECT
waitms 200
RESET LED_ROSSO

Wait 1

'READ 2
SET LED_VERDE
RESET CHIP_SELECT
SPIout Reg_Part_Number, 1
SPIin Byte_Ricevuto_2, 1
SET CHIP_SELECT
waitms 200
RESET LED_VERDE

waitms 400

IF Byte_Ricevuto_1 = Byte_Ricevuto_2 THEN
Byte_Ricevuto_1 = 11
Byte_Ricevuto_2 = 22
SET LED_ROSSO
WAIT 10
END IF

END SUB

'_______________________________________________________________________________________
SUB SCRIVI_LEGGI_E_CONFRONTA()

Valore_Scritto = 11
Valore_Letto = 22

'WRITE ROSSO
SET LED_ROSSO

RESET CHIP_SELECT
waitms 1
while PINB.4=1
wend
SPIout Reg_Sync_W, 1
waitms 1
SPIout Valore_Scritto, 1
waitms 1
SET CHIP_SELECT

Waitms 200
RESET LED_ROSSO

'READ VERDE
SET LED_VERDE
Waitms 1
RESET CHIP_SELECT
Waitms 1
'while PINB.4=1
'wend
SPIout Reg_Sync_R, 1
waitms 1
SPIin Valore_Letto, 1
Waitms 1
SET CHIP_SELECT

waitms 200
RESET LED_VERDE

IF Valore_Scritto = Valore_Letto THEN
Valore_Scritto = 11
Valore_Letto = 22
SET LED_ROSSO
WAIT 5
RESET LED_ROSSO
WAIT 1
END IF

END SUB

'_______________________________________________________________________________________


'_______________________________________________________________________________________


'_____________________________


Last edited by pinkfloyd11 on Mon Mar 16, 2015 6:22 pm; edited 1 time in total
Back to top
View user's profile
pinkfloyd11

Bascom Member



Joined: 02 Jul 2007
Posts: 248

italy.gif
PostPosted: Thu Mar 12, 2015 1:43 pm    Post subject: Reply with quote

please remove this message
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum