Code:
'****************************************************************
'* Name : Anaren Air Module.PBP
'* Date : 10/30/2010
'* Version : PIC12F683 on protoPCB, 1.0
'* Notes : This routine uses DEBUGIN from PC to send SPI data to control
'* the Anaren Transceiver Module A1101R09*. The idea is to first load all
'* pertinent information to configure the module then using DEBUGIN to
'* control the transmitter ON/OFF, mod or w/o mod, baud rate and PA level.
'*
'****************************************************************
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
OSCCON = %01110001 ' Osc 8Mhz
ANSEL = %00000000 ' A/D turned OFF
ADCON0 = %10000000 ' Right justified and OFF
CMCON0 = 7 ' Analog comparators off
GPIO = %00001001 '
TRISIO = %00001001 '
DEFINE OSC 8
INCLUDE "modedefs.bas"
' DEBUG Defines for Transmitter
DEFINE DEBUG_REG GPIO
DEFINE DEBUG_BIT 1 ' GPIO 1 Pin#6
DEFINE DEBUG_BAUD 19200
DEFINE DEBUG_MODE 1 ' 1 = inverted, 0 = true
' DEBUG Defines for Receiver
DEFINE DEBUGIN_REG GPIO
DEFINE DEBUGIN_BIT 3 ' GPIO 3 Pin#4
DEFINE DEBUGIN_BAUD 19200
DEFINE DEBUGIN_MODE 1 ' 1 = inverted, 0 = true
' Alias pin assignments
SCLK VAR GPIO.4 ' SPI bus clock on Pin#3
MOSI VAR GPIO.5 ' SPI bus data to device on Pin#2
MISO VAR GPIO.0 ' SPI bus data from module on Pin#7
_CSN VAR GPIO.2 ' SPI bus select on Pin#5
' Alias SPI variables
Address VAR BYTE
Add VAR BYTE
mode var BYTE
register VAR BYTE
cnt VAR BYTE
value VAR BYTE
' Setup outputs
_CSN = 1 ' S_SEL set to idle HIGH
Add = $0
Value = 0
mode = $0
PAUSE 500
'/////////////////////////////////////////////////////////////////////////
' Register setup
' This routine loads all the register values derived from the TI Smart RF
' calculations. Load all mode values here. Takes 19.6ms to load
' Highlights: (08:$32, Async transparent mode), (0A:$48, CH#72, 916.396MHz)
' (15:$43, Dev = 39KHz)
'/////////////////////////////////////////////////////////////////////////
FOR Address = 0 to $2E
SELECT CASE Address
CASE 0: mode = $0B : CASE 1: mode = $2E : CASE 2: mode = $0C
CASE 3: mode = $47 : CASE 4: mode = $D3 : CASE 5: mode = $91
CASE 6: mode = $3D : CASE 7: mode = $04 : CASE 8: mode = $22
CASE 9: mode = $00 : CASE $0A: mode = $48 : CASE $0B: mode = $08
CASE $0C: mode = $00 : CASE $0D: mode = $22 : CASE $0E: mode = $B1
CASE $0F: mode = $3B : CASE $10: mode = $CA : CASE $11: mode = $83
CASE $12: mode = $90 : CASE $13: mode = $22 : CASE $14: mode = $F8
CASE $15: mode = $43 : CASE $16: mode = $07 : CASE $17: mode = $30
CASE $18: mode = $18 : CASE $19: mode = $16 : CASE $1A: mode = $6C
CASE $1B: mode = $43 : CASE $1C: mode = $40 : CASE $1D: mode = $91
CASE $1E: mode = $87 : CASE $1F: mode = $6B : CASE $20: mode = $F8
CASE $21: mode = $56 : CASE $22: mode = $10 : CASE $23: mode = $E9
CASE $24: mode = $2A : CASE $25: mode = $00 : CASE $26: mode = $1F
CASE $27: mode = $41 : CASE $28: mode = $00 : CASE $29: mode = $59
CASE $2A: mode = $7F : CASE $2B: mode = $3F : CASE $2C: mode = $81
CASE $2D: mode = $35 : CASE $2E: mode = $09
END SELECT
_CSN = 0 ' Enable Select bit
GOSUB chip_status ' Allow data transfer when device ready
SHIFTOUT MOSI,SCLK,1,[Address,mode]
_CSN = 1 ' Disable Select bit
NEXT Address
' Additional setups
_CSN = 0 ' Enable Select bit
GOSUB chip_status ' Allow data transfer when device ready
SHIFTOUT MOSI,SCLK,1,[$7E,$8E] ' Set PA output to 0dBm
SHIFTOUT MOSI,SCLK,1,[$33] ' Calibrate synthesizer then turn OFF
_CSN = 1 ' Disable Select bit
'/////////////////////////////////////////////////////////////////////////
' Main test program loop
' Use DEBUG to monitor on Realterm set to Port 4 and 19200,8,1,N on laptop
' USB port nearest DVD player.
' Command type examples:
' Turn ON TX: 0 53 0
' Turn OFF TX: 0 54 0
' Change CH#: 4 n 0 ' n=CH# 0~130
' Change mod type: 1 16 202 ' 38.4KB 1st entry
' 1 17 131 ' 38.4KB 2nd entry
'
' Change PA level: 1 126 3 ' -30dBm
' 1 126 14 ' -20dBm
' 1 126 30 ' -15dBm
' 1 126 39 ' -10dBm
' 1 126 142 ' 0dBm
' 1 126 205 ' +5dBm
' 1 126 199 ' +7dBm
' 1 126 192 ' +10dBm
'/////////////////////////////////////////////////////////////////////////
Main:
DEBUGIN 10000, Main,[add,Address,mode] ' Loop here until PC data RX'd.
SELECT CASE Add
CASE 0: GOTO single
CASE 1: GOTO burst
CASE 2: GOTO multi
CASE 3: GOTO CH_change
CASE 4: GOTO CH_change_mod
END SELECT
single: ' Sends only the Address value to the module. Takes 173us.
_CSN = 0 ' Enable Select bit
GOSUB chip_status ' Allow data transfer when device ready
SHIFTOUT MOSI,SCLK,1,[Address]
_CSN = 1 ' Disable Select bit
DEBUG "Address value sent to module ",DEC Address,13,10
GOTO Main
burst: ' Sends Address and mode values together to the module. Takes 340us
_CSN = 0 ' Enable Select bit
GOSUB chip_status ' Allow data transfer when device ready
SHIFTOUT MOSI,SCLK,1,[Address,mode]
_CSN = 1 ' Disable Select bit
DEBUG "Address and Mode value sent to module ",DEC Address, " and ", DEC mode,13,10
GOTO Main
multi: ' Sends Address and mode values sequentually to the module
_CSN = 0 ' Enable Select bit
GOSUB chip_status ' Allow data transfer when device ready
SHIFTOUT MOSI,SCLK,1,[Address]
_CSN = 1 ' Disable Select bit
PAUSEUS 50
_CSN = 0 ' Enable Select bit
WHILE MISO : WEND ' Allow data transfer when device ready
SHIFTOUT MOSI,SCLK,1,[mode]
_CSN = 1 ' Disable Select bit
GOTO Main
CH_change: ' Changes channel based on channel number input. Takes 1.19ms
_CSN = 0 ' Enable Select bit
GOSUB chip_status ' Allow data transfer when device ready
SHIFTOUT MOSI,SCLK,1,[$36] ' Turn OFF TX
SHIFTOUT MOSI,SCLK,1,[$12,$B0] ' Setup for no modulation
SHIFTOUT MOSI,SCLK,1,[$0A,Address] ' Enter CH#
SHIFTOUT MOSI,SCLK,1,[$31] ' SFSTXON, Cal synth and stby
SHIFTOUT MOSI,SCLK,1,[$35] ' STX, turn ON transmitter
_CSN = 1 ' Disable Select bit
GOTO Main
CH_change_mod: ' Changes channel and enables modulation. Takes 1.19ms
_CSN = 0 ' Enable Select bit
GOSUB chip_status ' Allow data transfer when device ready
SHIFTOUT MOSI,SCLK,1,[$36] ' Turn OFF TX
SHIFTOUT MOSI,SCLK,1,[$12,$90] ' Setup for modulation
SHIFTOUT MOSI,SCLK,1,[$0A,Address] ' Enter CH#
SHIFTOUT MOSI,SCLK,1,[$31] ' SFSTXON, Cal synth and stby
SHIFTOUT MOSI,SCLK,1,[$35] ' STX, turn ON transmitter
_CSN = 1 ' Disable Select bit
GOTO Main
chip_status: ' Wait until module ready to accept new data
IF MISO = 1 THEN chip_status
RETURN
END
Here's the schematic to go with that code:
Code:
main:
m = m+1
GOSUB TX_FIFO
Grn = 1
GOSUB transmit ' Takes 176us to send command
Grn = 0
WHILE !GDO0: WEND ' Goes High after Preamble and Sync Word sent
WHILE GDO0 = 1 ' and takes 2ms before sending packet.
Grn = 1 ' Wait for TX to complete
WEND ' 1 byte packet takes 233us to TX
Grn = 0
GOSUB Clear_TX_FIFO
PAUSE 100
GOTO main
'========================== Data packet loading ========================
' Burst data into TX FIFO register $3F by adding $40
TX_FIFO:
_CSN = 0 ' Enable Select bit
GOSUB chip_status ' Allow data transfer when device ready
SHIFTOUT MOSI,SCLK,1,[$7F,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0A,_
$0B,$0C,$0D,$0E,$0F,$10,$11,$12,$13,$14,$15,$16,$17,m]
_CSN = 1 ' Disable Select bit
RETURN
'======================== Transmit routine ==============================
transmit:
_CSN = 0 ' Enable Select bit
GOSUB chip_status ' Allow data transfer when device ready
SHIFTOUT MOSI,SCLK,1,[$35] ' STX, turn ON transmitter
_CSN = 1 ' Disable Select bit
RETURN
Clear_TX_FIFO:
_CSN = 0 ' Enable Select bit
GOSUB chip_status ' Allow data transfer when device ready
SHIFTOUT MOSI,SCLK,1,[$3B] ' Flush out TX FIFO buffer
_CSN = 1 ' Disable Select bit
RETURN
Bookmarks