TRW 24G in bascom

i have problem, i can’t transmit and receive data. can anyone help me

this my transmit source code:

$regfile = “8535def.dat”

$baud = 9600

$crystal = 12000000

Ce Alias Portc.4

Cs Alias Portc.3

Dr Alias Pinc.2

Clk Alias Portc.1

Dat Alias Portc.0

Dat_pin Alias Pinc.0

Declare Sub Config_fullmode

Declare Sub Send_byte

Declare Sub Read_byte

Declare Sub Config_tr

Declare Sub General_config

Config Pinc.4 = Output

Config Pinc.3 = Output

Config Pinc.2 = Input

Config Pinc.1 = Output

Config Pinc.0 = Output

Dim Jumlah As Byte

Dim Dat_out As Byte

Dim I As Byte

Dim J As Byte

Dim Data_print As Bit

'shockburst configuration

Dim Data2_w As Byte , Data1_w As Byte

Dim Addr2_1 As Byte , Addr2_2 As Byte , Addr2_3 As Byte , Addr2_4 As Byte , Addr2_5 As Byte

Dim Addr1_1 As Byte , Addr1_2 As Byte , Addr1_3 As Byte , Addr1_4 As Byte , Addr1_5 As Byte

Dim Addr_w As Byte , Crc_length As Bit , Crc_en As Bit '6-1-1

'general configuration

Dim Rx2_en As Bit , Cm As Bit , Rfdr_sb As Bit , Xo_f As Byte , Rf_pwr As Byte '1-1-1-3-2

Dim Rf_ch As Byte , Rx_en As Bit '7-1

Dim Dat0 As Byte

Ce = 0

Cs = 0

Clk = 0

Dat = 0

Waitms 500

Data2_w = 8

Data1_w = 8 'length data

Addr2_5 = &H00

Addr2_4 = &H00

Addr2_3 = &H00

Addr2_2 = &H00

Addr2_1 = &H00

Addr1_5 = &H00 'address

Addr1_4 = &H00

Addr1_3 = &H00

Addr1_2 = &H00

Addr1_1 = &H00

Addr_w = 40 'length address

Crc_length = 1 'lenght crc

Crc_en = 1

Rx2_en = 0

Cm = 1 'direct/shockburst

Rfdr_sb = 1 'data rate kbps/mbps

Xo_f = 3 'crystal freq

Rf_pwr = 2 'db

Rf_ch = &H55 '0-83

Rx_en = 1

Call Config_fullmode

Waitms 10

‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’’

Goto Kirim

‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’’

Kirim: 'sub send

Rx_en = 0

Call Config_tr

'Kirim2:

Do

Dat0 = &H01

‘’‘’‘’‘’‘’‘’‘’’

Ce = 0

Cs = 0

Waitus 10

Ce = 1

Waitus 10

Dat_out = Addr1_1 'addr1

Call Send_byte

Dat_out = Addr1_2 'addr2

Call Send_byte

Dat_out = Addr1_3 'addr3

Call Send_byte

Dat_out = Addr1_4 'addr4

Call Send_byte

Dat_out = Addr1_5 'addr5

Call Send_byte

Dat_out = Dat0 'data

Call Send_byte

Waitus 10

Ce = 0

Loop

End

Sub Config_tr

Cs = 1

Ce = 0

Config Dat_pin = Input

Waitms 10

Dat = Rx_en

Waitus 1

Clk = 1

Waitus 1

Clk = 0

Cs = 0

End Sub

Sub Send_byte

For I = 1 To 8

Waitus 1

'Ce = 0

Clk = 1

Rotate Dat_out , Left

Data_print = Dat_out And 1

’ Print Data_print;

Dat = Data_print

Waitus 1

'Ce = 1

Clk = 0

Next

Clk = 0

’ Print “”

End Sub

Sub Config_fullmode

Cs = 1

Ce = 0

Config Dat_pin = Output

Waitms 10

Dat_out = Data2_w

Call Send_byte

Dat_out = Data1_w

Call Send_byte

Dat_out = Addr2_5

Call Send_byte

Dat_out = Addr2_4

Call Send_byte

Dat_out = Addr2_3

Call Send_byte

Dat_out = Addr2_2

Call Send_byte

Dat_out = Addr2_1

Call Send_byte

Dat_out = Addr1_5

Call Send_byte

Dat_out = Addr1_4

Call Send_byte

Dat_out = Addr1_3

Call Send_byte

Dat_out = Addr1_2

Call Send_byte

Dat_out = Addr1_1

Call Send_byte

Shift Addr_w , Left , 1

Addr_w = Addr_w Or Crc_length

Shift Addr_w , Left , 1

Dat_out = Addr_w Or Crc_en

Call Send_byte

Dat_out = Rx2_en

Shift Dat_out , Left , 1

Dat_out = Dat_out Or Cm

Shift Dat_out , Left , 1

Dat_out = Dat_out Or Rfdr_sb

Shift Dat_out , Left , 3

Dat_out = Dat_out Or Xo_f

Shift Dat_out , Left , 2

Dat_out = Dat_out Or Rf_pwr

Call Send_byte

Dat_out = Rf_ch

Shift Dat_out , Left , 1

Dat_out = Dat_out Or Rx_en

Call Send_byte

Cs = 0

End Sub

and receive source code:

$regfile = “8535def.dat”

$baud = 9600

$crystal = 12000000

Ce Alias Portd.6

Cs Alias Portd.5

Dr Alias Pind.4

Clk Alias Portd.3

Dat Alias Portd.2

Dat_pin Alias Pind.2

Declare Sub Config_fullmode

Declare Sub Send_byte

Declare Sub Read_byte

Declare Sub Config_tr

Declare Sub General_config

Declare Sub Geser

Config Lcd = 16 * 2

Config Lcdpin = Pin , Rs = Portc.1 , E = Portc.3 , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7

Config Pind.6 = Output

Config Pind.5 = Output

Config Pind.4 = Input

Config Pind.3 = Output

Config Pind.2 = Output

'Config Portb = Output

Dim Jumlah As Byte

Dim Dat_out As Byte

Dim I As Byte

Dim J As Byte

Dim Data_print As Bit

Dim N As Byte , X As Byte

'shockburst configuration

Dim Data2_w As Byte , Data1_w As Byte

Dim Addr2_1 As Byte , Addr2_2 As Byte , Addr2_3 As Byte , Addr2_4 As Byte , Addr2_5 As Byte

Dim Addr1_1 As Byte , Addr1_2 As Byte , Addr1_3 As Byte , Addr1_4 As Byte , Addr1_5 As Byte

Dim Addr_w As Byte , Crc_length As Bit , Crc_en As Bit '6-1-1

'general configuration

Dim Rx2_en As Bit , Cm As Bit , Rfdr_sb As Bit , Xo_f As Byte , Rf_pwr As Byte '1-1-1-3-2

Dim Rf_ch As Byte , Rx_en As Bit '7-1

Dim Dat0 As Byte

Cls

Ce = 0

Cs = 0

Clk = 0

Dat = 0

Waitms 500

Data2_w = 8

Data1_w = 8 ’

Addr2_5 = &H00

Addr2_4 = &H00

Addr2_3 = &H00

Addr2_2 = &H00

Addr2_1 = &H00

Addr1_5 = &H00 'address

Addr1_4 = &H00

Addr1_3 = &H00

Addr1_2 = &H00

Addr1_1 = &H00

Addr_w = 40 ’

Crc_length = 1 ’

Crc_en = 1

Rx2_en = 0

Cm = 1 'direct/shockburst

Rfdr_sb = 1 'data rate kbps/mbps

Xo_f = 3 'crystal freq

Rf_pwr = 1 'db

Rf_ch = &H55 '0-83

Rx_en = 1

Call Config_fullmode

Waitms 10

‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’’

Goto Terima

‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’’

Terima:

Rx_en = 1

Call Config_tr

Config Dat_pin = Input

Waitms 10

Do

Cs = 0

Ce = 1

Waitus 10

While Dr = 0

Wend

Ce = 0

While Dr = 1

Call Read_byte

If Dat_out = &H01 Then

Cls

Lcd “terima”

Goto Terima

End If

Wend

Loop

Sub Read_byte

Dat_out = 1

For I = 1 To 8

Waitus 1

Clk = 1

Shift Dat_out , Left

Dat_out = Dat_out Or Dat_pin

Waitus 1

Clk = 0

Next

Clk = 0

End Sub

Sub Config_tr

Cs = 1

Ce = 0

Config Dat_pin = Input

Waitms 10

Dat = Rx_en

Waitus 1

Clk = 1

Waitus 1

Clk = 0

Cs = 0

End Sub

Sub Config_fullmode

Cs = 1

Ce = 0

Config Dat_pin = Input

Waitms 10

Dat_out = Data2_w

Call Send_byte

Dat_out = Data1_w

Call Send_byte

Dat_out = Addr2_5

Call Send_byte

Dat_out = Addr2_4

Call Send_byte

Dat_out = Addr2_3

Call Send_byte

Dat_out = Addr2_2

Call Send_byte

Dat_out = Addr2_1

Call Send_byte

Dat_out = Addr1_5

Call Send_byte

Dat_out = Addr1_4

Call Send_byte

Dat_out = Addr1_3

Call Send_byte

Dat_out = Addr1_2

Call Send_byte

Dat_out = Addr1_1

Call Send_byte

Shift Addr_w , Left , 1

Addr_w = Addr_w Or Crc_length

Shift Addr_w , Left , 1

Dat_out = Addr_w Or Crc_en

Call Send_byte

Dat_out = Rx2_en

Shift Dat_out , Left , 1

Dat_out = Dat_out Or Cm

Shift Dat_out , Left , 1

Dat_out = Dat_out Or Rfdr_sb

Shift Dat_out , Left , 3

Dat_out = Dat_out Or Xo_f

Shift Dat_out , Left , 2

Dat_out = Dat_out Or Rf_pwr

Call Send_byte

Dat_out = Rf_ch

Shift Dat_out , Left , 1

Dat_out = Dat_out Or Rx_en

Call Send_byte

Cs = 0

End Sub

End

please help me, and what wrong in my program?

You’ll need to give a little more information. What kind of circuit have you connected? What have you tried already? What do you think the problem may be?

Try limiting your source code down to parts where you think there may be a problem, and convert it to English (including variables, labels, and functions!). It’s too much to give a guess at with that much code - It could be anything!

paran:
$regfile = “8535def.dat”

$baud = 9600

$crystal = 12000000

Is the device a 90S8535 or an atmega8535? If you are using the At90S8535 (8 MHz) then you are severely overclocking the micro.

radbrad:
You’ll need to give a little more information. What kind of circuit have you connected? What have you tried already? What do you think the problem may be?

Try limiting your source code down to parts where you think there may be a problem, and convert it to English (including variables, labels, and functions!). It’s too much to give a guess at with that much code - It could be anything!

i want to transmit data from current sensor with TRW 24G, i think circuit does’t matter. i don’t know where is the problem located. in my configuration or in my code to transmit or receive. i give LED to indicate data transmitted and received but nothing happen. in code, i just send data H01 to try tranceive data. i write full my code in order to you are know if there are wrong code per line, i am sorry if too much :smiley:

kirim = sub sending

teima= sub receive

newbie123:

paran:
$regfile = “8535def.dat”

$baud = 9600

$crystal = 12000000

Is the device a 90S8535 or an atmega8535? If you are using the At90S8535 (8 MHz) then you are severely overclocking the micro.

i use ATMega8535 with 12 MHz of crystal

The circuit has everything to do with it. Unless you’ve used the module before, it’s highly likely to be part of the problem.

Case in point: Upon simple inspection of the MCU and radio datasheets, there is an obvious mismatch. The processor cannot run faster than 8MHz at 3.3V, but the radio must operate at 3.3V. Are you level shifting the voltage? If not, the chips will not operate and you are most likely damaging one or the other.

paran:
$regfile = “8535def.dat”

Shouldn’t the above line be:

$regfile = "m8535.dat"

I could be wrong, I know very little about bascom.( I only have a very old Demo version) The AT90S8535 and the atmega8535 are two different avr devices. There will be differences when compiling the code, one example in particular is the UART in the AT90S8535 and the USART in the Atmega8535.

If you are familiar with assembly, I can give you the code that is working for your atmega, running at 4MHz.

Newbie123 is correct, it won’t work when compiling for the wrong chip