I have 433Mhz Transmitter Receiver to send some data.
On Transmitter side:
[code:1:54c5b8dff2]
$regfile = "ATtiny25.DAT"
$crystal = 1000000
'Variables=======================================================
Dim But_int As Bit
Dim Rf_data As Byte
Dim Rf_string As String * 20
Dim Rf_char As String * 1
Dim Idx As Byte
Tx_pin Alias Portb.1
But_pin Alias Pinb.2
Init:
'ports settings----------------------------------------------------------------
Config Portb.0 = Input
Config Portb.1 = Output
Config Portb.2 = Input
Config Portb.4 = Input
'adc settings------------------------------------------------------------------
Config Adc = Single , Prescaler = Auto , Reference = Internal_2.56_nocap
'interrupts settings-----------------------------------------------------------
Config Int0 = Rising
On Int0 Int0_isr
Enable Int0
Enable Interrupts
Do
If But_int = 1 Then
Rf_string = "123" + Chr(13)
Gosub Send_sony_string
But_int = 0
Enable Int0
End If
Loop
End
Send_sony_one:
Tx_pin = 0
Waitus 6000
Tx_pin = 1
Waitus 12000
Tx_pin = 0
Return
Send_sony_zero:
Tx_pin = 0
Waitus 600
Tx_pin = 1
Waitus 6000
Tx_pin = 0
Return
Send_sony_start:
Tx_pin = 0
Waitus 12000
Tx_pin = 1
Waitus 24000
Tx_pin = 0
Return
Send_sony_char:
'start bit
Gosub Send_sony_start
'data bits
If Rf_char.0 = 1 Then
Gosub Send_sony_one
Else
Gosub Send_sony_zero
End If
If Rf_char.1 = 1 Then
Gosub Send_sony_one
Else
Gosub Send_sony_zero
End If
If Rf_char.2 = 1 Then
Gosub Send_sony_one
Else
Gosub Send_sony_zero
End If
If Rf_char.3 = 1 Then
Gosub Send_sony_one
Else
Gosub Send_sony_zero
End If
If Rf_char.4 = 1 Then
Gosub Send_sony_one
Else
Gosub Send_sony_zero
End If
If Rf_char.5 = 1 Then
Gosub Send_sony_one
Else
Gosub Send_sony_zero
End If
If Rf_char.6 = 1 Then
Gosub Send_sony_one
Else
Gosub Send_sony_zero
End If
If Rf_char.7 = 1 Then
Gosub Send_sony_one
Else
Gosub Send_sony_zero
End If
Return
Int0_isr:
Waitms 50 'debounce
If But_pin = 1 Then
Disable Int0
But_int = 1
End If
Return
[/code:1:54c5b8dff2]
On Receiver side:
[code:1:54c5b8dff2]
$regfile = "m128def.dat"
$crystal = 4000000
$baud = 9600
'Variables========================================================
Const Buf_size = 20
'ring buffer
Dim Rf_buf_tail As Word
Dim Rf_buf_head As Word
Dim Rf_buf_count As Word
Dim Rf_rx_buf(buf_size) As Byte
'sony protocol variables
Dim Idx As Byte
Dim Sony_bit As Bit
'interrupt flags
Dim Got_serial As Bit
Dim Got_rf As Bit
'uart variables
Dim Serial_char As String * 1 ' one char for serial communication data
Dim Serial_string As String * 20 ' 7 chars string for the full serial communication work
Dim Rf_data As Byte
Rx1 Alias Pind.2
Led1 Alias Portc.7
Init:
'Ports Settings-----------------------------------------------------------------
Ddra = &H00 'b0-b7 - inputs
Ddrb = &H17
Ddre = &H0E 'b0-input(rx),b4-b7-inputs
Ddrf = &H00
'Interrupts Settings------------------------------------------------------------
Eicra.isc20 = 0 : Eicra.isc21 = 1 'falling edge
On Int2 Int2_isr
Enable Int2
Enable Interrupts
'check if chip is alive
Print "Start"
Do
If Got_rf = 1 Then
Got_rf = 0
Print Serial_string
Rf_buf_count = 0
Serial_string = ""
End If
Loop
End
Get_sony_bit:
While Rx1 = 1
Idx = 0
Wend
While Rx1 = 0
Waitus 100
Incr Idx
Wend
If Idx < 80 Then
Idx = 0
Else
Idx = 1
End If
Return
Get_sony_data:
Waitus 1500
'valid start bit
If Rx1 = 0 Then
While Rx1 = 0
NOP
Wend
'get command
Gosub Get_sony_bit
Rf_data.0 = Idx
Gosub Get_sony_bit
Rf_data.1 = Idx
Gosub Get_sony_bit
Rf_data.2 = Idx
Gosub Get_sony_bit
Rf_data.3 = Idx
Gosub Get_sony_bit
Rf_data.4 = Idx
Gosub Get_sony_bit
Rf_data.5 = Idx
Gosub Get_sony_bit
Rf_data.6 = Idx
Gosub Get_sony_bit
Rf_data.7 = Idx
End If
Return
Int2_isr:
Disable Int2
Gosub Get_sony_data
If Rf_data = Chr(13) Then 'r
Got_rf = 1
Else
If Rf_buf_count < Buf_size Then 'no overflow
Serial_string = Serial_string + Chr(rf_data)
Incr Rf_buf_count
End If
End If
Enable Int2
Return
[/code:1:54c5b8dff2]
As you see I send 123. But on receiver side in a terminal I see 112233 twice every char I send. I thought the problem in the terminal but
If Serial_string = " 112233" Then
Toggle Led1
End If
Proves the terminal is OK.
On scope I see nice clean signals all as expected.
I struggle over several days cant bit it. Please help.
[b:54c5b8dff2][color=red:54c5b8dff2](BASCOM-AVR version : 2.0.7.6 )[/b:54c5b8dff2][/color:54c5b8dff2]
↧