CC1101: come inviare e ricevere comandi via SPI?

Sezione dedicata al sistema di sviluppo BASCOM-AVR per i micro AVR
At90s, Attiny, Atmega e Xmega

CC1101: come inviare e ricevere comandi via SPI?

Postby PinkFloyd11 » 12 Mar 2015, 16:38

Salve,
sto iniziando un progetto con il transceiver TI CC1101.

Il primo step è scrivere le funzioni di lettura e scrittura. Partendo dalla lettura, dal datasheet leggo:

All transactions on the SPI interface start with a header byte containing a R/W¯ bit, a burst access bit (B), and a 6-bit address (A5 – A0).

Per cui dovrebbe essere un byte tipo [a][b][address 6 bit].

Uso delle costanti per settare i singoli bit [a] e [b]:
const READ_SINGLE = &H0080 '0x80 -> 1000 0000
const WRITE_BURST = &H0040 '0x40 -> 0100 0000
const READ_BURST = &H00C0 '0xC0 -> 1100 0000
const CONFIG_REG = &H0080 '0x80 -> 1000 0000
const STATUS_REG = &H00C0 '0xC0 -> 1100 0000

e altre per gli address:
const CC1101_SRES = &H0030' 0x30' Reset chip.
const CC1101_SFSTXON = &H0031' 0x31' Enable and calibrate frequency synthesizer
const CC1101_SXOFF = &H0032' 0x32' Turn off crystal oscillator.
const CC1101_SCAL = &H0033' 0x33' Calibrate frequency synthesizer and turn it off
const CC1101_SRX = &H0034' 0x34' Enable RX. const CC1101_STX = &H0035'
const CC1101_SIDLE = &H0036' 0x36' Exit RX / TX, turn off frequency synthesizer and exit

Dal datasheet leggo che:

When the header byte, data byte, or command strobe is sent on the SPI interface, the chip status byte is sent by the CC1101 on the SO pin.
The status byte contains key status signals, useful for the MCU.


Quindi dopo l'invio di un comando dovrei ricevere lo status register:
STATUS BYTE [7] [6][5][4] [3][2][1][0]
7: [CHIP_RDY]
6-4: [STATE]
3_0: [FREE FIFO BYTE]

In Bascomese dovrebbe essere:

Code: Select all
CONFIG Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 16
SPIINIT

Dim Dato_da_Inviare as byte
Dim Dato_Ricevuto as byte

Dato_da_Inviare  = READ_SINGLE
Dato_da_Inviare = Dato_da_Inviare AND CC1101_SRES
 
SPIOUT Dato_da_Inviare, 1
SPIIN Dato_Ricevuto , 1


E' corretto?
PinkFloyd11
 
Posts: 5
Joined: 25 Feb 2013, 09:44

Re: CC1101: come inviare e ricevere comandi via SPI?

Postby einstein » 15 Mar 2015, 08:49

@pinkfloyd
sei sicuro che la Config Spi sia esatta. hai modo di vedere se la spi genera i segnali compatibili con quelli che richiede il chip? le tensioni sono compatibili?

Un'altra cosa. ti consiglio di presentarti nella apposita sezione visto che sei al tuo primo post.
User avatar
einstein
 
Posts: 88
Joined: 01 Mar 2014, 15:10
Location: Siracusa

Re: CC1101: come inviare e ricevere comandi via SPI?

Postby deluca » 15 Mar 2015, 17:56

Ciao pink,
benvenuto al tuo primo post.
Come ti ha suggerito einstein ti invito a presentarti nella sezione apposita del forum.
Per poterti aiutare devi darci altre indicazioni: micro, clock, tensione, e se possibile posta lo schema di collegamento tra il micro e il CC.

Tutto ciò per aiutarci ad aiutarti. ciao
Ciao
Il mio sito: http://www.delucagiovanni.com ......e la chat: chat/
User avatar
deluca
Site Admin
 
Posts: 1104
Joined: 19 Jun 2011, 10:44
Location: 95123 - Catania (Italy)

Re: CC1101: come inviare e ricevere comandi via SPI?

Postby PinkFloyd11 » 16 Mar 2015, 12:50

Code: Select all
'////////////////////////////////////////////
' SPI SEND and RECEIVE COMMAND
'////////////////////////////////////////////

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

Open "COMB.0:57600,8,n,1" For Output As #1
Open "COMB.1:57600,8,n,1" For Input As #2

Print #1 , "CC1101 TEST BOARD"
Config Spi = Soft , Din = Pinb.3 , Dout = Portb.4 , Ss = Portb.2 , Clock = Portb.5
'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
             while PINB.3=1
             wend

            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
                 while PINB.3=1
                 wend

            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

      Print #1, "PRIMA LETTURA= "; Byte_Ricevuto_1
      Print #1, "SECONDA LETTURA= "; Byte_Ricevuto_2
      Print #1, ""

      SET LED_ROSSO
      WAIT 5
      RESET LED_ROSSO


 END IF

END SUB

'_______________________________________________________________________________________
SUB  SCRIVI_LEGGI_E_CONFRONTA()

  Valore_Scritto = 11
  Valore_Letto = 22

  'WRITE ROSSO
  SET LED_ROSSO

        RESET CHIP_SELECT

               while PINB.3=1'while(mosi)
               wend

               SPIout Reg_Sync_W, 1
               SPIout Valore_Scritto, 1

        SET CHIP_SELECT

  Waitms 10
  RESET LED_ROSSO

  'Print #1, "VALORE SCRITTO= "; Valore_Scritto

  'READ VERDE
  SET LED_VERDE

        RESET CHIP_SELECT

            while PINB.3=1 'while(mosi)
            wend

            SPIout Reg_Sync_R, 1
            SPIin Valore_Letto, 1
        SET CHIP_SELECT

  waitms 200
  RESET LED_VERDE

  Print #1, "VALORE LETTO= "; Valore_Letto
  Print #1, ""

  IF Valore_Scritto = Valore_Letto THEN

       Print #1, "VALORI UGUALI= "

       SET LED_ROSSO
       WAIT 5
       RESET LED_ROSSO
       WAIT 1
 END IF

END SUB

'_______________________________________________________________________________________


'_______________________________________________________________________________________


'_______________________________________________________________________________________
Attachments
Cattura3.PNG
Cattura3.PNG (3.18 KiB) Viewed 7593 times
Cattura2.PNG
Cattura2.PNG (3.21 KiB) Viewed 7593 times
Cattura1.PNG
Cattura1.PNG (1.63 KiB) Viewed 7593 times
PinkFloyd11
 
Posts: 5
Joined: 25 Feb 2013, 09:44

Re: CC1101: come inviare e ricevere comandi via SPI?

Postby deluca » 17 Mar 2015, 20:27

Cosa vuoi dire con questi grafici PROTEUSSIANI?

Hai risolto?
Ciao
Il mio sito: http://www.delucagiovanni.com ......e la chat: chat/
User avatar
deluca
Site Admin
 
Posts: 1104
Joined: 19 Jun 2011, 10:44
Location: 95123 - Catania (Italy)

Re: CC1101: come inviare e ricevere comandi via SPI?

Postby PinkFloyd11 » 17 Mar 2015, 20:48

Purtroppo non ancora...
Si riferiscono alla simulazione del codice postato.
PinkFloyd11
 
Posts: 5
Joined: 25 Feb 2013, 09:44

Re: CC1101: come inviare e ricevere comandi via SPI?

Postby Leonardo » 17 Mar 2015, 21:51

PinkFloyd11 wrote:Quindi dopo l'invio di un comando dovrei ricevere lo status register:
STATUS BYTE [7] [6][5][4] [3][2][1][0]
7: [CHIP_RDY]
6-4: [STATE]
3_0: [FREE FIFO BYTE]


Lo Status Register viene trasmesso durante e non dopo l'invio del comando

Image

Ciao
Il mio blog di elettronica: http://electro-logic.blogspot.it
User avatar
Leonardo
 
Posts: 502
Joined: 29 May 2013, 22:31
Location: Parma


Return to BASCOM-AVR

Who is online

Users browsing this forum: No registered users and 4 guests

cron