go_away

Author Topic: 2.4GHz Spectrum Analyzer - need GLCD from china importer - ebay  (Read 1711 times)

0 Members and 1 Guest are viewing this topic.

Offline TrickyNekroTopic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,207
  • Helpful? 15
  • 1.6L Peugeot 307 tuner
Hello to everybody,
 I'm trying to build a 2.4GHz communication module via an AVR controller (whatever with at least 4KB memory)
and I've seen a nice project on CYWUSB6935 at ELEKTOR...

The IC isn't only a transceiver. It has a Receive Signal Strength Indicator feature...
And this is what I'm going to show here in this example code:

Code: [Select]
' --------[ Device Config]----------------------------------------------------

$regfile = "m8535.dat"
$crystal = 16000000
$baud = 9600


' --------[ LCD Config ]------------------------------------------------------

Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.5
Config Lcdpin = Pin , Db7 = Portc.4 , E = Portc.1 , Rs = Portc.0
Config Lcd = 20 * 4


' --------[ SPI Config ]------------------------------------------------------

Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 1 , Clockrate = 16 , Noss = 1


' --------[ General Port Config ]---------------------------------------------

Config Portb = Output
Config Portb.2 = Input


' --------[ Port Sympolic Name ]----------------------------------------------

Resetline Alias Portb.0
Ss Alias Portb.4


' --------[ Constants ]-------------------------------------------------------

Const Reg_id = &H00
Const Reg_control = &H03
Const Reg_data_rate = &H04
Const Reg_config = &H05
Const Reg_serdes_ctl = &H06
Const Reg_rx_int_en = &H07
Const Reg_rx_int_stat = &H08
Const Reg_rx_data_a = &H09
Const Reg_rx_valid_a = &H0A
Const Reg_rx_data_b = &H0B
Const Reg_rx_valid_b = &H0C
Const Reg_tx_int_en = &H0D
Const Reg_tx_int_stat = &H0E
Const Reg_tx_data = &H0F
Const Reg_tx_valid = &H10
Const Reg_pn_code = &H11
Const Reg_threshold_l = &H19
Const Reg_threshold_h = &H1A
Const Reg_wake_en = &H1C
Const Reg_wake_stat = &H1D
Const Reg_analog_ctl = &H20
Const Reg_channel = &H21
Const Reg_rssi = &H22
Const Reg_pa = &H23
Const Reg_crystal_adj = &H24
Const Reg_vco_cal = &H26
Const Reg_pwr_ctl = &H2E
Const Reg_carrier_detect = &H2F
Const Reg_clock_manual = &H32
Const Reg_clock_enable = &H33
Const Reg_syn_lock_cnt = &H38
Const Reg_mid = &H3C


' --------[ Variables ]-------------------------------------------------------

Dim Brust As Bit
Dim Rw_select As Bit
Dim Address As Byte
Dim Carrier(8) As Byte
Dim Rssi_sample As Byte
Dim Channel As Byte
Dim I As Byte , J As Byte
Dim Bytenum As Byte
Dim Sum As Word


' --------[ Initialize ]------------------------------------------------------

Resetline = 1
' Set reset line to logic high to enable the IC
Ss = 1
' Set SS line to logic high to avoid data float
Brust = 0
Rw_select = 0
Address = 0
For I = 1 To 8
 Carrier(i) = 0
Next
' Set everything variable to zero to avoid possible float

' LCD messaging
Cls
Cursor Off
Lcd " CYWUSB6935  Report "

' Initialize SPI
Spiinit

' --------[ Main Program ]----------------------------------------------------

Do

J = 1

For Channel = 20 To 39
 Gosub Channel_set
 Gosub Rssi
 Locate 2 , J : Lcd Rssi_sample ; "  "
 J = J + 2
Next
Waitms 100

Loop





End                                                         ' End



' --------[ SubRoutines ]-----------------------------------------------------

Address_up:
' Check for Brust SPI mode
 If Brust = 1 Then
  Address = Address + 64
 End If
' Check for Read/Write sequence
' If 0 then Read command is issued
' If 1 then Write command is issued
 If Rw_select = 1 Then
  Address = Address + 128
 End If

Return                                                      ' Return


Spi_read:
' Read the device
 Ss = 0
' Set SS line low since it's disabled from the hardware SPI
 Spiout Address , 1
' Send the address to the CYWUSB6935
' Note that the command bits 6 and 7 are controller via the
' Address_up subroutine
 Spiin Carrier(1) , Bytenum
' Read what is sent to the AVR
' The number of bytes received is determined by Bytenum variable
 Ss = 1
' Set SS line to logic high and stop any transaction

Return                                                      ' Return


Spi_write:
' Write to the device
 Ss = 0
' Set SS line low since it's disabled from the hardware SPI
 Spiout Address , 1
' Send the address to the CYWUSB6935
' Note that the command bits 6 and 7 are controller via the
' Address_up subroutine
 Spiout Carrier(1) , Bytenum
' Write some bytes to the device
' The number of bytes sent is determined by Bytenum variable
 Ss = 1
' Set SS line to logic high and stop any transaction

Return                                                      ' Return


Get_pn_code:
' Reading the PN Code
' Set the variables for "PN Code" register reading
 Brust = 1
' Brust = 1 because we read 8 bytes in one circle
 Rw_select = 0
' We READ the pn code
 Bytenum = 8
' Eight bytes to read
 Address = Reg_pn_code
' See constant table above

' Issue everything needed to read the device
' and the certain register
 Gosub Address_up
 Gosub Spi_read

' LCD messaging
 Lowerline
 Lcd "PN: "
 For I = 8 To 1 Step -1
  Lcd Hex(carrier(i))
 Next

 Return                                                     'Return


Read_analog_contol:
' Reading the analog control register
' Set the variables for this task
 Brust = 0
' Only one byte to read
 Rw_select = 0
' We READ the analog control register
 Bytenum = 1
' One byte to read
 Address = Reg_analog_ctl
' See constant table above

' Issue everything needed to read the device
' and the certain register
 Gosub Address_up
 Gosub Spi_read
' LCD messaging
 Thirdline
 Lcd "An Cont: " ; Bin(carrier(1))

Return


Write_analog_contol:
' Writing to the analog control register
' Set the variables for this task
 Brust = 0
' Only one byte to write
 Rw_select = 1
' We WRITE the analog control register
 Bytenum = 1
' One byte to read
 Address = Reg_analog_ctl
' See constant table above

' Issue everything needed to read the device
' and the certain register
 Gosub Address_up
 Gosub Spi_write

Return                                                      ' return


Read_carrier_detect:
' Reading the carrier control register
' Set the variables for this task
 Brust = 0
' Only one byte to read
 Rw_select = 0
' We READ the analog control register
 Bytenum = 1
' One byte to read
 Address = Reg_carrier_detect
' See constant table above

' Issue everything needed to read the device
' and the certain register
 Gosub Address_up
 Gosub Spi_read
' LCD messaging
 Fourthline
 Lcd "Car Det: " ; Bin(carrier(1))

Return                                                      ' Return


Write_carrier_detect:
' Writing to the carrier control register
' Set the variables for this task
 Brust = 0
' Only one byte to write
 Rw_select = 1
' We WRITE the analog control register
 Bytenum = 1
' One byte to read
 Address = Reg_carrier_detect
' See constant table above

' Issue everything needed to read the device
' and the certain register
 Gosub Address_up
 Gosub Spi_write

Return                                                      ' Return


Channel_set:
' Writing to the channel register
' Set the variables for this task
 Brust = 0
' Only one byte to write
 Rw_select = 1
' We WRITE the channel register
 Bytenum = 1
' One byte to write
 Address = Reg_channel
' See constant table above
 Carrier(1) = Channel
' The byte sent is the Channel number setted above

' Issue everything needed to read the device
' and the certain register
 Gosub Address_up
 Gosub Spi_write

Return                                                      ' Return

Rssi:
' Receive Signal Strength Indicator
' First access analog control to permit writing to
' the carrier detect register.
' In this register we  enable the receiver of the IC
 Carrier(1) = &B01000000
' Set Reg Write Control to 1
 Gosub Write_analog_contol

 Sum = 0
 For I = 1 To 20
  Gosub Receive_mode_on
  Brust = 0
 ' Only one byte to write
  Rw_select = 0
 ' We READ the RSSI register
  Bytenum = 1
 ' One byte to read
  Address = Reg_channel
 ' See constant table above
  Gosub Address_up
  Gosub Spi_read

  If Carrier(1) < 32 Then
   Carrier(1) = &B10000000
    Gosub Write_carrier_detect
    Waitus 55
   Brust = 0
   ' Only one byte to write
   Rw_select = 0
   ' We READ the RSSI register
   Bytenum = 1
   ' One byte to read
   Address = Reg_channel
   ' See constant table above
    Gosub Address_up
    Gosub Spi_read
   Carrier(1) = Carrier(1) - 32
   Sum = Sum + Carrier(1)
   Carrier(1) = &B00000000
    Gosub Write_carrier_detect

  Else
   Carrier(1) = Carrier(1) - 32
   Sum = Sum + Carrier(1)
  End If

  Gosub Receive_mode_off

 Next

 Rssi_sample = Sum / 20

Return                                                      ' Return


Receive_mode_on:

 Carrier(1) = &B10000000
 ' Set the variables for this task
  Brust = 0
 ' Only one byte to write
  Rw_select = 1
 ' We WRITE the channel register
  Bytenum = 1
 ' One byte to read
  Address = Reg_control
 ' See constant table above

 Gosub Address_up
 Gosub Spi_write

Return                                                      'Return


Receive_mode_off:

 Carrier(1) = &B00000000
 ' Set the variables for this task
  Brust = 0
 ' Only one byte to write
  Rw_select = 1
 ' We WRITE the channel register
  Bytenum = 1
 ' One byte to read
  Address = Reg_control
 ' See constant table above

 Gosub Address_up
 Gosub Spi_write

Return                                                      'Return



The thing is that this code supports a 20x4 LCD...

I need a GLCD so anyone finding something good on e-bay can be very very helpful...

Thanks in advance,

Lefteris
For whom the interrupts toll...


P.S. I've been inactive for almost a year... Don't give promises but I'll try to complete my tutorials. I'll let you know when..

Cheers!

 


Get Your Ad Here

data_list