[img:2bb9138065]http://members.home.nl/hobbycorner/images/Bascom_forum/MQTT_display.jpg[/img:2bb9138065]
Made a light Bascom MQTT client as a display. Using a Raspberry as a MQTT broker in my own network.
Two universal routines, Publish(topic,message) and Subscribe(topic).
If you want you can test the MQTT functionality with MQTT.fx - a JAVA MQTT client
Arduino Mega with W5100 ethernetshield and a HX8357C display is used. The TFT-routines are from HKipnik.
The only call to a display is
[code:1:2bb9138065]Call display_message(msg2)[/code:1:2bb9138065]
Display of text is only handled in that routine so you could use your own display, LCD 16x2, I2C display etc.
Arrays are used to fill Publish and Subscribe, so these routines can be used in other clients.
A keep alive time is 70 seconds. Before the end of the keep alive time a PINGREQuest is send. A PINGRESponse clears the keep alive and ping timers.
[code:1:2bb9138065]'Light Bascom MQTT client - TFT with HX8357c
'HX8357C routines from HKipnik
'connect / subscribe / publish / pingreq / (disconnect)
'publish and subscribe to Topic home/lcd
'Hardware: Arduino Mega 2560 with W5100 Ethernet shield
'Connecting to a Raspberry Mosquitto MQTT Broker - 192.168.0.98
'Ben Zijlstra - 2016
$regfile = "m2560def.dat" ' specify the used micro
$crystal = 16000000 ' used crystal frequency
$baud = 56700 ' use baud rate
$hwstack = 200
$swstack = 220
$framesize = 250
Config Portb.4 = Output
Wiz5100_cs Alias Portb.4
Wiz5100_cs = 1
Waitms 500
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 0
Spiinit
Config Tcpip = Noint , Mac = 12.128.12.33.46.74 , Ip = 192.168.0.221 , Submask = 255.255.255.0 , Gateway = 192.168.0.1 , _
Localport = 1000 , Tx = $55 , Rx = $55 , Chip = W5100 , Spi = 1 , Cs = Portb.4
Dim Idx As Byte
Dim Bclient As Byte
Dim Result As Word
Dim S As Long
Dim Tempw As Word
Dim Helpw As Word
Dim Status As Long
Dim Z(255) As Byte
Dim B As Byte
Dim Y As Byte
Dim Messagelen As Byte
Dim Msg2 As String * 200
Dim Emptyline As String * 40
Dim Dsp_txt(11) As String * 40
Dim Line_counter As Byte
'keep alive
Dim Keepalive_counter As Long
Dim Pingresponse_counter As Long
Dim Pub_ar(255) As Byte
Dim Sub_ar(100) As Byte
Dim Msg As String * 150
Dim Topic As String * 100
Keepalive_counter = 0
Pingresponse_counter = 0
Line_counter = 1
Emptyline = Space(40)
Dim Lcd_textt As String * 200
Const Cdebug = 1 'for debug purpose
Const C2dbug = 1
Const Keepalive = 60
Const Keepalive_ticks = Keepalive * 15000 'keep alive * second
Const Keepalive_ticks_pingresponse = Keepalive_ticks + 30000
Const Client_id = "Bascom-Client"
'Connect is {016}(&H10) MQTT Control Packet type
' {025} Length message
' {000} Length protocol name MSB
' {004} Length protocol name LSB
' MQTT Protocol name
' {004} Protocol level
' {002} Connect flags (002 = Clean Session)
' {000} Keep alive MSB
' {070} Keep alive LSB (70 seconds)
' {000}
' {013} Length client-ID
' Bascom-client (Client-ID)
Const Connect = "{016}{025}{000}{004}MQTT{004}{002}{000}{070}{000}{013}Bascom-Client"
Const Confirm = "{048}{031}{000}{008}home/lcdReceived MQTT-message"
Const Pingreq = "{192}{000}" '&HC0 &H00 - ping request - keep alive
Const Disconnect = "{224}{000}" '&HE0 &H00
Declare Sub Display_message(byval Msg2 As String)
Declare Sub Publish(byval Topic As String , Byval Msg As String)
Declare Sub Subscribe(byval Topic As String)
'*******************************************************************************
'Display Mode
'*******************************************************************************
Const Lcd_mode = 4 '1=Portrait 2=Portrait 180° 3=landscape 4=landscape 180°
Const Lcd_driver = 2 '1=HX8357B 2=HX8357C
Const Sd_card = 0
'*******************************************************************************
$include "TFTDriverHX8357_declarations.inc"
'*******************************************************************************
'Init the Display
'*******************************************************************************
Call Lcd_init()
Call Lcd_clear(black)
'*******************************************************************************
' Display landscape
'*******************************************************************************
Call Lcd_clear(black)
Call Lcd_text( "BASCOM-AVR MQTT-example" , 5 , 1 , 2 , Dodgerblue , Black , 1)
Call Lcd_line(5 , 23 , 475 , 23 , 1 , Yellow)
Call Lcd_text( "home/lcd" , 5 , 30 , 2 , Floralwhite , Black , 1)
Call Lcd_text( " " , 460 , 1 , 2 , Black , Red , 1)
Print "Programm start"
Print
Idx = 0
Bclient = Getsocket(idx , Sock_stream , 7000 , 0) 'Open socket TCP (sock_stream), local port 7000
Result = Socketconnect(idx , 192.168.0.98 , 1883) 'the IP-address of the MQTT broker and the port
Call Lcd_text( " " , 460 , 1 , 2 , Black , Red , 1)
Do
Tempw = Socketstat(idx , 0) 'get status
If Tempw = Sock_established Then
#if C2dbug
Print "Socket established with MQTT broker"
#endif
Call Lcd_text( "Socket established with MQTT broker " , 5 , 300 , 2 , Floralwhite , Black , 1)
Exit Do
End If
Loop
#if Cdebug
Print "Connect"
#endif
Call Lcd_text( "Connect" , 5 , 300 , 2 , Floralwhite , Black , 1)
Result = Tcpwrite(idx , Connect) 'connect to the broker
Do
Tempw = Socketstat(idx , Sel_recv) 'get received bytes
If Tempw > 0 Then 'if there is something received
Helpw = Tcpread(idx , S , Tempw) 'read
Status = S And &H0000FFFF 'two bytes
If Status = &H00000220 Then
#if C2dbug
Print "Connect ACK"
#endif
Call Lcd_text( "Connect ACK " , 5 , 300 , 2 , Floralwhite , Black , 1)
Exit Do
End If
End If
Loop
Call Lcd_text( "Subscribe to home/lcd " , 5 , 300 , 2 , Floralwhite , Black , 1)
Call Subscribe( "home/lcd")
Call Lcd_text( " " , 460 , 1 , 2 , Black , Green , 1)
Wait 4
#if C2dbug
Print "Publish"
#endif
Call Publish( "home/lcd" , "TFT-screen online")
Call Lcd_text( " " , 5 , 300 , 2 , Floralwhite , Black , 1)
'reset the keep alive
'is something published in the subscribed topic?
Do
Tempw = Socketstat(idx , Sel_recv) 'get received bytes
If Tempw = 2 Then '2 bytes, a reaction of a pingrequest
Helpw = Tcpread(idx , S , 2)
Status = S And &H0000FFFF 'two bytes
If Status = &H000000D0 Then
#if Cdebug
Print "Pingresponse received"
#endif
Call Lcd_text( " " , 460 , 1 , 2 , Black , Green , 1)
Pingresponse_counter = 0 'start pingresponse time again
End If
End If
If Tempw > 2 Then 'if there is something received
#if Cdebug
Print "something arrives"
Print "Tempw = " ; Tempw
#endif
For B = 1 To Tempw
Helpw = Tcpread(idx , Z(b) , 1)
Next B
#if Cdebug
'Print Hex(z(1)) '&H30 type of MQTT packet
Print "Total length message including Topic " ; Z(2)
'Print Hex(z(3))
Print "Length of Topic " ; Z(4)
#endif
Messagelen = Z(2) - Z(4)
Decr Messagelen
Decr Messagelen
#if Cdebug
Print "Message length " ; Messagelen
#endif
Z(4) = Z(4) + 4
Print
Print "Topic: ";
For Y = 5 To Z(4)
Print Chr(z(y));
Next Y
Print
Msg2 = ""
Z(4) = Z(4) + 1
Print "Message: ";
For Y = Z(4) To Messagelen + 12
Print Chr(z(y));
Msg2 = Msg2 + Chr(z(y))
Next Y
Print
Print
'don't confirm the Bascom-MQTT-client online message
'and don't confirm the confirm message Wink
If Msg2 <> "Bascom-MQTT-client online" Then
If Msg2 <> "Received MQTT-message" Then
Call Display_message(msg2)
#if C2dbug
Print "Confirm"
#endif
Result = Tcpwrite(idx , Confirm) 'publish the message
Keepalive_counter = 0
Pingresponse_counter = 0
End If
End If
End If
'keep alive pingrequest
If Keepalive_counter > Keepalive_ticks Then 'keep alive is 70 seconds (see connect header)
#if C2dbug
Print "Pingreq"
#endif
Call Lcd_text( " " , 460 , 1 , 2 , Black , Red , 1)
Result = Tcpwrite(idx , Pingreq) 'pingrequest
Keepalive_counter = 0
End If
If Pingresponse_counter > Keepalive_ticks_pingresponse Then
Print "No pingresponses! - Reboot"
Goto 0 'reboot
End If
'Keep alive counter
Incr Keepalive_counter
'pingresponse counter
Incr Pingresponse_counter
Loop
'you will never reach these lines at the moment
#if Cdebug
Print "Disconnect"
#endif
Result = Tcpwrite(idx , Disconnect) 'disconnect
Wait 4
Socketdisconnect Idx 'disconnect socket
End
Sub Publish(byval Topic , Byval Msg)
Local Topic_len As Byte
Local Message_len As Byte
Local Temp As Byte
Local Temp2 As Byte
Local Temps As String * 1
Local Temp3 As Byte
Topic_len = Len(topic)
Message_len = Len(msg)
Temp = Topic_len + Message_len
Temp3 = Temp + 4 'length for tcpwrite
Incr Temp
Incr Temp
'Const Publish = "{048}{028}{000}{008}home/lcdTFT-screen online"
Pub_ar(1) = "{048}"
Pub_ar(2) = Temp
Pub_ar(3) = "{000}"
Pub_ar(4) = Topic_len
'topic
For Temp = 1 To Topic_len
Temp2 = Temp + 4
Temps = Mid(topic , Temp , 1)
Pub_ar(temp2) = Asc(temps)
Next Temp
'message
For Temp = 1 To Message_len
Incr Temp2
Temps = Mid(msg , Temp , 1)
Pub_ar(temp2) = Asc(temps)
Next Temp
#if C2dbug
Print "Publish"
#endif
Result = Tcpwrite(idx , Pub_ar(1) , Temp3) 'publish the message
Keepalive_counter = 0 : Pingresponse_counter = 0 'reset the keep alive
End Sub
Sub Subscribe(byval Topic)
Local Topic_len As Byte
Local Temp As Byte
Local Temp2 As Byte
Local Temps As String * 1
Local Temp3 As Byte
Topic_len = Len(topic)
Temp3 = Topic_len + 7
Temp = Temp3 - 2
'Const Subscribe = "{130}{013}{000}{002}{000}{008}home/lcd{000}"
Sub_ar(1) = "{130}"
Sub_ar(2) = Temp
Sub_ar(3) = "{000}"
Sub_ar(4) = "{002}"
Sub_ar(5) = "{000}"
Sub_ar(6) = Topic_len
'topic
For Temp = 1 To Topic_len
Temp2 = Temp + 6
Temps = Mid(topic , Temp , 1)
Sub_ar(temp2) = Asc(temps)
Next Temp
Print "Temp2 = " ; Temp2
Incr Temp2
Sub_ar(temp2) = "{000}"
#if C2dbug
Print "Subscribe"
#endif
Result = Tcpwrite(idx , Sub_ar(1) , Temp3) 'subscribe to topic
Do
Tempw = Socketstat(idx , Sel_recv) 'get received bytes
If Tempw > 0 Then 'if there is something received
Helpw = Tcpread(idx , S , Tempw) 'read
Status = S And &H00FFFFFF 'three bytes
If Status = &H00000390 Then
#if C2dbug
Print "Subscribe ACK"
#endif
Keepalive_counter = 0
Pingresponse_counter = 0 'reset the keep alive
Exit Do
End If
End If
Loop
End Sub
Sub Display_message(byval Msg2 As String)
Local Verticalpos As Word
Local Dsp_help As Byte
Verticalpos = 60
Lcd_textt = Left(msg2 , 39)
Emptyline = Space(40)
Mid(emptyline , 1) = Lcd_textt
Dsp_txt(line_counter) = Emptyline
Line_counter = Line_counter + 1
If Line_counter = 11 Then
For Dsp_help = 1 To 10
Dsp_txt(dsp_help) = Dsp_txt(dsp_help + 1)
Next Dsp_help
Line_counter = 10
End If
'display all lines
For Dsp_help = 1 To 10
Call Lcd_text(dsp_txt(dsp_help) , 5 , Verticalpos , 2 , Floralwhite , Black , 1) '10 lines x 39 characters
Verticalpos = Verticalpos + 24
Next Dsp_help
End Sub
$include "TFTDriverHX8357_functions.inc"
$include "FontDigital20x32.font" '7 segments
$include "Fontfont12x16.font"
$include "Fontfont25x32.font"
$include "FontArial11x14.font"
[/code:1:2bb9138065]
Have fun
Ben Zijlstra
(next, a Ultra ultra ultra light MQTT single shot client)
↧
Share your working BASCOM-AVR code here : Ultra Light MQTT client : REPLY
↧
BASCOM-AVR : hardware SPI : REPLY
You don`t configure SS pin as Output
Also NOSS=1 is used... so
This is normal AVR behavior if SPI is in Master mode but something pull SS pin down then for preventing collisions SPI is switched automatycally to SLAVE mode.
You can read about this in datasheet (page 158 for Mega328P) ;)
↧
↧
BASCOM-AVR : LoadLabel with part >64K : NEWTOPIC
I'm keeping a database in DATA statements, and need the ability to switch between 10 databases, like this:
[code:1:a7035444a4]
DBType = "US"
Gosub SetDatabase
WhatINeed = Lookupstr(MyIndex,CurrentDB_a)
WhatINeed2 = Lookup(MyIndex, CurrentDB_b)
' ---------
Sub SetDatabase:
Select Case DBType
Case "US"
CurrentDB_a = Loadlabel(Data_US_a)
CurrentDB_b = Loadlabel(Data_US_b)
Case "EU"
CurrentDB_a = Loadlabel(Data_EU_a)
CurrentDB_b = Loadlabel(Data_EU_b)
End Select
End Sub
' ----------
Data_US_a:
DATA "123", "124", "125", "126"
DATA "127", "128", "129", "130"
Data_US_b:
DATA 131, 132, 133, 135
DATA 137, 139, 140, 141
Data_EU_a:
DATA "142", "144", "145", "146"
DATA "148", "150", "151", "152"
Data_EU_b:
DATA 155, 156, 158, 160
DATA 166, 167, 168, 170
[/code:1:a7035444a4]
Problem is, I need to implement this in a 128K part, and Loadlabel apparently only works in <64K parts. Best I can tell, I might need to do something with RAMPZ, but I couldn't find an example of usage I could apply to the code I'm working on. Is there a way around this? Or is there a way to rewrite this to avoid the limitation? Any help appreciated!
[b:a7035444a4][color=red:a7035444a4](BASCOM-AVR version : 2.0.7.8 )[/b:a7035444a4][/color:a7035444a4]
↧
Share your working BASCOM-AVR code here : Ultra Light MQTT client : REPLY
excellent Ben. I got the thin client going.
Thank you for your research and sharing. This saves me a lot of work.
↧
BASCOM-AVR : LoadLabel with part >64K : REPLY
Hi,
Have a look at [url=http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=10239&highlight=loadlabel]this topic[/url], and then to the 1 reply from Mcselec.
↧
↧
BASCOM-AVR : hardware SPI : REPLY
Tnx for this info.
NOSS = 0 cured this
I read the BASCOM help only:
1 or 0. Use 1 when you do not want the SS signal to be generated in master mode.
And my conclusion was, that SS is not used by SPI at all (and I do not need it)
In my HW SS pin is open but unfortunately I did not set the pullup
Tnx again
Guenter
↧
BASCOM-AVR : Problem with NRF24L01P : NEWTOPIC
Hi
I use the Bascom to set up NRF24L01P.
But I have a problem!
Tx Code:
[code:1:15ae7dfa46]
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Nordic nRF24L01 data link demo in Enhanced Shockburst mode
' By Evert Dekker 2007 nRF24L01@Evertdekker dotje com
' Created with Bascom-Avr: 1.11.8.3
'------------------------------------------------------------------
$regfile = "M32def.dat"
$crystal = 16000000
$baud = 9600
$hwstack = 40
$swstack = 20
$framesize = 40
'=== Declare sub routines
Declare Sub R_register(byval Command As Byte , Byval C_bytes As Byte)
Declare Sub W_register(byval C_bytes As Byte)
'=== Constante ===
'Define nRF24L01 interrupt flag's
Const Idle_int = &H00 'Idle, no interrupt pending
Const Max_rt = &H10 'Max #of Tx Retrans Interrupt
Const Tx_ds = &H20 'Tx Data Sent Interrupt
Const Rx_dr = &H40 'Rx Data Received
'SPI(nRF24L01) commands
Const Read_reg = &H00 'Define Read Command To Register
Const Write_reg = &H20 'Define Write Command To Register
Const Rd_rx_pload = &H61 'Define Rx Payload Register Address
Const Wr_tx_pload = &HA0 'Define Tx Payload Register Address
Const Flush_tx = &HE1 'Define Flush Tx Register Command
Const Flush_rx = &HE2 'Define Flush Rx Register Command
Const Reuse_tx_pl = &HE3 'Define Reuse Tx Payload Register Command
Const Nop_comm = &HFF 'Define No Operation , Might Be Used To Read Status Register
'SPI(nRF24L01) registers(addresses)
Const Config_nrf = &H00 'Config' register address
Const En_aa = &H01 'Enable Auto Acknowledgment' register address
Const En_rxaddr = &H02 'Enabled RX addresses' register address
Const Setup_aw = &H03 'Setup address width' register address
Const Setup_retr = &H04 'Setup Auto. Retrans' register address
Const Rf_ch = &H05 'RF channel' register address
Const Rf_setup = &H06 'RF setup' register address
Const Status = &H07 'Status' register address
Const Observe_tx = &H08 'Observe TX' register address
Const Cd = &H09 'Carrier Detect' register address
Const Rx_addr_p0 = &H0A 'RX address pipe0' register address
Const Rx_addr_p1 = &H0B 'RX address pipe1' register address
Const Rx_addr_p2 = &H0C 'RX address pipe2' register address
Const Rx_addr_p3 = &H0D 'RX address pipe3' register address
Const Rx_addr_p4 = &H0E 'RX address pipe4' register address
Const Rx_addr_p5 = &H0F 'RX address pipe5' register address
Const Tx_addr = &H10 'TX address' register address
Const Rx_pw_p0 = &H11 'RX payload width, pipe0' register address
Const Rx_pw_p1 = &H12 'RX payload width, pipe1' register address
Const Rx_pw_p2 = &H13 'RX payload width, pipe2' register address
Const Rx_pw_p3 = &H14 'RX payload width, pipe3' register address
Const Rx_pw_p4 = &H15 'RX payload width, pipe4' register address
Const Rx_pw_p5 = &H16 'RX payload width, pipe5' register address
Const Fifo_status = &H17 'FIFO Status Register' register address
'Various
Const True = 1
Const False = 0
'=== Config hardware ===
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 1
'Software SPI is NOT working with the nRF24L01, use hardware SPI only, but the SS pin must be controlled by our self
Config Pinb.2 = Output 'CE pin is output
Config Pinb.3 = Output 'SS pin is output
Config Pinb.4 = Input 'IRQ pin is input
'Config Pinc.3 = Input 'TX/RX Device _select
Ce Alias Portb.2
Ss Alias Portb.3
Irq Alias Pinb.4
'Txrx_device Alias Pinc.3
Dim Txrx_device As Bit : Txrx_device = 1
Spiinit 'init the spi pins
Set Ce
Waitms 10 'Wait a moment until all hardware is stable
Reset Ce 'Set CE pin low
Reset Ss 'Set SS pin low (CSN pin)
Dim D_bytes(33) As Byte , B_bytes(33) As Byte 'Dim the bytes use for SPI, D_bytes = outgoing B_bytes = Incoming
Dim Temp As Byte , W As Word
Dim Packet_count As Byte
If Txrx_device = True Then Goto Main_tx 'Is this the RX or TX device?
'===Main rx==========================================================================================================================
Main_rx:
Call R_register(status , 1) 'Read STATUS register
Print "Rx_device" 'Send to terminal who i'm
Reset Ce 'Set CE low to access the registers
Gosub Setup_rx 'Setup the nRF24L01 for RX
Waitms 2 'Add a delay before going in RX
Set Ce 'Set nRF20L01 in RX mode
Do 'Main loop for RX
If Irq = 0 Then 'Wait until IRQ occurs, pin becomes low on interrupt
Reset Ce 'Receiver must be disabled before reading pload
Do 'Loop until all 3 fifo buffers are empty
Call R_register(rd_rx_pload , 5) 'Read 5 bytes RX pload register
Print "Pload : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) 'Print the pload
Call R_register(fifo_status , 1) 'Read FIFO_STATUS
Loop Until B_bytes(1).0 = True 'Test or RX_EMPTY bit is true, RX FIFO empty
D_bytes(1) = Write_reg + Status 'Reset the RX_DR status bit
D_bytes(2) = &B01000000 'Write 1 to RX_DR bit to reset IRQ
Call W_register(2)
Set Ce 'Enable receiver again
Waitms 2
End If
'Gosub Dump_registers 'Unremark me for debugging
Loop
Return
'===Main tx==========================================================================================================================
Main_tx:
Print "TX_device" 'Send to terminal who i'm
D_bytes(1) = Flush_tx 'Flush the TX_fifo buffer
Call W_register(1)
D_bytes(1) = Write_reg + Status 'Reset the IRQ bits
D_bytes(2) = &B00110000
Call W_register(2)
Do 'Main loop for TX
Incr Packet_count 'Increase the send packet counter, for test only
If Packet_count > 254 Then Packet_count = 0
Gosub Setup_tx 'Setup the nrf240l01 for TX
D_bytes(1) = Wr_tx_pload 'Put 5 bytes in the TX pload buffer
D_bytes(2) = &HAA 'Byte 1
D_bytes(3) = &HBB 'Byte 2
D_bytes(4) = &HCC 'Byte 3
D_bytes(5) = &H11 'Byte 4
D_bytes(6) = Packet_count 'Byte 5 will be increase every loop
Call W_register(6) 'Write 6 bytes to register
Waitms 2
Set Ce 'Set CE for a short moment to transmit the fifo buffer
Waitms 1 '
Reset Ce '
Waitms 100 'Some delay to read the output on the terminal, line can be removed for max. speed
W = 0 'Counter for time out
Do
If Irq = 0 Then
Call R_register(status , 1)
Temp = B_bytes(1) And &B01110000 'Mask the IRQ bits out the status byte
Select Case Temp 'Which IRQ occurs
Case Max_rt 'MAX_RT
Print "Maximum number of TX retries, Flussing the TX buffer now !"
D_bytes(1) = Flush_tx 'Flush the TX buffer
Call W_register(1)
D_bytes(1) = Write_reg + Status
D_bytes(2) = &B00010000 'Clear the MAX_RT IRQ bit
Call W_register(2)
Exit Do
Case Tx_ds 'TX_DS
Print "Packet " ; Packet_count ; " send and ACK received."
D_bytes(1) = Write_reg + Status
D_bytes(2) = &B00100000 'Clear the TX_DS IRQ bit
Call W_register(2)
Exit Do
Case Else 'Other IRQ ??
Print "Other irq " ; Bin(temp)
D_bytes(1) = Flush_tx 'Flush the TX buffer
Call W_register(1)
D_bytes(1) = Write_reg + Status
D_bytes(2) = &B00110000 'Clear both MAX_RT, TX_DS bits
Call W_register(2)
End Select
End If
Waitms 1 'Time out waiting for IRQ 1ms * 100
Incr W 'Increment W
If W > 100 Then 'Waited for 100ms
Print "No irq response from RF20L01 within 100ms"
Exit Do 'Exit the wait loop
End If
Loop
Loop
Return
'=== Sub routines ===
Sub W_register(byval C_bytes As Byte) 'Write register with SPI
Reset Ss 'Manual control SS pin, set SS low before shifting out the bytes
Spiout D_bytes(1) , C_bytes 'Shiftout the data bytes trough SPI , C_bytes is the amount bytes to be written
Set Ss 'Set SS high
End Sub
Sub R_register(byval Command As Byte , Byval C_bytes As Byte) As Byte 'C_bytes = Count_bytes, number off bytes to be read
Reset Ss 'Manual controle SS pin, set low before shifting in/out the bytes
Spiout Command , 1 'First shiftout the register to be read
Spiin B_bytes(1) , C_bytes 'Read back the bytes from SPI sended by nRF20L01
Set Ss 'Set SS back to high level
End Sub
Setup_rx: 'Setup for RX
D_bytes(1) = Write_reg + Rx_addr_p0 'RX adress for pipe0
D_bytes(2) = &H34
D_bytes(3) = &H43
D_bytes(4) = &H10
D_bytes(5) = &H10
D_bytes(6) = &H01
Call W_register(6) 'Send 6 bytes to SPI
D_bytes(1) = Write_reg + En_aa 'Enable auto ACK for pipe0
D_bytes(2) = &H01
Call W_register(2)
D_bytes(1) = Write_reg + En_rxaddr 'Enable RX adress for pipe0
D_bytes(2) = &H01
Call W_register(2)
D_bytes(1) = Write_reg + Rf_ch 'Set RF channel
D_bytes(2) = 40
Call W_register(2)
D_bytes(1) = Write_reg + Rx_pw_p0 'Set RX pload width for pipe0
D_bytes(2) = 5
Call W_register(2)
D_bytes(1) = Write_reg + Rf_setup 'Setup RF-> Output power 0dbm, datarate 2Mbps and LNA gain on
D_bytes(2) = &H0F
Call W_register(2)
D_bytes(1) = Write_reg + Config_nrf 'Setup CONFIG-> PRX=1(RX_device), PWR_UP=1, CRC 2bytes, Enable CRC
D_bytes(2) = &H0F
Call W_register(2)
Return
Setup_tx: 'Setup for TX
D_bytes(1) = Write_reg + Tx_addr 'TX adress
D_bytes(2) = &H34
D_bytes(3) = &H43
D_bytes(4) = &H10
D_bytes(5) = &H10
D_bytes(6) = &H01
Call W_register(6)
D_bytes(1) = Write_reg + Rx_addr_p0 'RX adress for pipe0
D_bytes(2) = &H34
D_bytes(3) = &H43
D_bytes(4) = &H10
D_bytes(5) = &H10
D_bytes(6) = &H01
Call W_register(6)
D_bytes(1) = Write_reg + En_aa 'Enable auto ACK for pipe0
D_bytes(2) = &H01
Call W_register(2)
D_bytes(1) = Write_reg + En_rxaddr 'Enable RX adress for pipe0
D_bytes(2) = &H01
Call W_register(2)
D_bytes(1) = Write_reg + Rf_ch 'Set RF channel
D_bytes(2) = 40
Call W_register(2)
D_bytes(1) = Write_reg + Rf_setup 'Setup RF-> Output power 0dbm, datarate 2Mbps and LNA gain on
D_bytes(2) = &H0F
Call W_register(2)
D_bytes(1) = Write_reg + Config_nrf 'Setup CONFIG-> PRX=0(TX_device), PWR_UP=1, CRC 2bytes, Enable CRC
D_bytes(2) = &H0E
Call W_register(2)
Return
Dump_registers: 'Dumps all nRF24L01 registers to the terminal, handy for debugging
Print "* Dump nRF24L01 Registers *"
Call R_register(config_nrf , 1)
Print "CONFIG : " ; Bin(b_bytes(1))
Call R_register(en_aa , 1)
Print "EN_AA : " ; Bin(b_bytes(1))
Call R_register(en_rxaddr , 1)
Print "EN_RXADDR : " ; Bin(b_bytes(1))
Call R_register(setup_aw , 1)
Print "SETUP_AW : " ; Bin(b_bytes(1))
Call R_register(setup_retr , 1)
Print "SETUP_RETR : " ; Bin(b_bytes(1))
Call R_register(rf_ch , 1)
Print "RF_CH : " ; B_bytes(1)
Call R_register(rf_setup , 1)
Print "RF_SETUP : " ; Bin(b_bytes(1))
Call R_register(status , 1)
Print "STATUS : " ; Bin(b_bytes(1))
Call R_register(observe_tx , 1)
Print "OBSERVE_TX : " ; Bin(b_bytes(1))
Call R_register(cd , 1)
Print "CD : " ; Bin(b_bytes(1))
Call R_register(rx_addr_p0 , 5)
Print "RX_ADDR_P0 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_addr_p1 , 5)
Print "RX_ADDR_P1 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_addr_p2 , 5)
Print "RX_ADDR_P2 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_addr_p3 , 5)
Print "RX_ADDR_P3 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_addr_p4 , 5)
Print "RX_ADDR_P4 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_addr_p5 , 5)
Print "RX_ADDR_P5 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(tx_addr , 5)
Print "TX_ADDR : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_pw_p0 , 5)
Print "RX_PW_P0 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_pw_p1 , 5)
Print "RX_PW_P1 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_pw_p2 , 5)
Print "RX_PW_P2 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_pw_p3 , 5)
Print "RX_PW_P3 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_pw_p4 , 5)
Print "RX_PW_P4 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_pw_p5 , 5)
Print "RX_PW_P5 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(fifo_status , 1)
Print "FIFO_STATUS : " ; Bin(b_bytes(1))
Return
[/code:1:15ae7dfa46]
Rx Code:
[code:1:15ae7dfa46]
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Nordic nRF24L01 data link demo in Enhanced Shockburst mode
' By Evert Dekker 2007 nRF24L01@Evertdekker dotje com
' Created with Bascom-Avr: 1.11.8.3
'------------------------------------------------------------------
$regfile = "M32def.dat"
$crystal = 16000000
$baud = 9600
$hwstack = 40
$swstack = 20
$framesize = 40
'=== Declare sub routines
Declare Sub R_register(byval Command As Byte , Byval C_bytes As Byte)
Declare Sub W_register(byval C_bytes As Byte)
'=== Constante ===
'Define nRF24L01 interrupt flag's
Const Idle_int = &H00 'Idle, no interrupt pending
Const Max_rt = &H10 'Max #of Tx Retrans Interrupt
Const Tx_ds = &H20 'Tx Data Sent Interrupt
Const Rx_dr = &H40 'Rx Data Received
'SPI(nRF24L01) commands
Const Read_reg = &H00 'Define Read Command To Register
Const Write_reg = &H20 'Define Write Command To Register
Const Rd_rx_pload = &H61 'Define Rx Payload Register Address
Const Wr_tx_pload = &HA0 'Define Tx Payload Register Address
Const Flush_tx = &HE1 'Define Flush Tx Register Command
Const Flush_rx = &HE2 'Define Flush Rx Register Command
Const Reuse_tx_pl = &HE3 'Define Reuse Tx Payload Register Command
Const Nop_comm = &HFF 'Define No Operation , Might Be Used To Read Status Register
'SPI(nRF24L01) registers(addresses)
Const Config_nrf = &H00 'Config' register address
Const En_aa = &H01 'Enable Auto Acknowledgment' register address
Const En_rxaddr = &H02 'Enabled RX addresses' register address
Const Setup_aw = &H03 'Setup address width' register address
Const Setup_retr = &H04 'Setup Auto. Retrans' register address
Const Rf_ch = &H05 'RF channel' register address
Const Rf_setup = &H06 'RF setup' register address
Const Status = &H07 'Status' register address
Const Observe_tx = &H08 'Observe TX' register address
Const Cd = &H09 'Carrier Detect' register address
Const Rx_addr_p0 = &H0A 'RX address pipe0' register address
Const Rx_addr_p1 = &H0B 'RX address pipe1' register address
Const Rx_addr_p2 = &H0C 'RX address pipe2' register address
Const Rx_addr_p3 = &H0D 'RX address pipe3' register address
Const Rx_addr_p4 = &H0E 'RX address pipe4' register address
Const Rx_addr_p5 = &H0F 'RX address pipe5' register address
Const Tx_addr = &H10 'TX address' register address
Const Rx_pw_p0 = &H11 'RX payload width, pipe0' register address
Const Rx_pw_p1 = &H12 'RX payload width, pipe1' register address
Const Rx_pw_p2 = &H13 'RX payload width, pipe2' register address
Const Rx_pw_p3 = &H14 'RX payload width, pipe3' register address
Const Rx_pw_p4 = &H15 'RX payload width, pipe4' register address
Const Rx_pw_p5 = &H16 'RX payload width, pipe5' register address
Const Fifo_status = &H17 'FIFO Status Register' register address
'Various
Const True = 1
Const False = 0
'=== Config hardware ===
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 1
'Software SPI is NOT working with the nRF24L01, use hardware SPI only, but the SS pin must be controlled by our self
Config Pina.3 = Output 'CE pin is output
Config Pina.2 = Output 'SS pin is output
Config Pina.1 = Input 'IRQ pin is input
'Config Pinc.3 = Input 'TX/RX Device _select
Ce Alias Porta.3
Ss Alias Porta.2
Irq Alias Pina.1
'Txrx_device Alias Pinc.3
Dim Txrx_device As Bit : Txrx_device = 0
Spiinit 'init the spi pins
Set Ce
Waitms 10 'Wait a moment until all hardware is stable
Reset Ce 'Set CE pin low
Reset Ss 'Set SS pin low (CSN pin)
Dim D_bytes(33) As Byte , B_bytes(33) As Byte 'Dim the bytes use for SPI, D_bytes = outgoing B_bytes = Incoming
Dim Temp As Byte , W As Word
Dim Packet_count As Byte
If Txrx_device = True Then Goto Main_tx 'Is this the RX or TX device?
'===Main rx==========================================================================================================================
Main_rx:
Call R_register(status , 1) 'Read STATUS register
Print "Rx_device" 'Send to terminal who i'm
Reset Ce 'Set CE low to access the registers
Gosub Setup_rx 'Setup the nRF24L01 for RX
Waitms 2 'Add a delay before going in RX
Set Ce 'Set nRF20L01 in RX mode
Do 'Main loop for RX
If Irq = 0 Then 'Wait until IRQ occurs, pin becomes low on interrupt
Reset Ce 'Receiver must be disabled before reading pload
Do 'Loop until all 3 fifo buffers are empty
Call R_register(rd_rx_pload , 5) 'Read 5 bytes RX pload register
Print "Pload : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) 'Print the pload
Call R_register(fifo_status , 1) 'Read FIFO_STATUS
Loop Until B_bytes(1).0 = True 'Test or RX_EMPTY bit is true, RX FIFO empty
D_bytes(1) = Write_reg + Status 'Reset the RX_DR status bit
D_bytes(2) = &B01000000 'Write 1 to RX_DR bit to reset IRQ
Call W_register(2)
Set Ce 'Enable receiver again
Waitms 2
End If
'Gosub Dump_registers 'Unremark me for debugging
Loop
Return
'===Main tx==========================================================================================================================
Main_tx:
Print "TX_device" 'Send to terminal who i'm
D_bytes(1) = Flush_tx 'Flush the TX_fifo buffer
Call W_register(1)
D_bytes(1) = Write_reg + Status 'Reset the IRQ bits
D_bytes(2) = &B00110000
Call W_register(2)
Do 'Main loop for TX
Incr Packet_count 'Increase the send packet counter, for test only
If Packet_count > 254 Then Packet_count = 0
Gosub Setup_tx 'Setup the nrf240l01 for TX
D_bytes(1) = Wr_tx_pload 'Put 5 bytes in the TX pload buffer
D_bytes(2) = &HAA 'Byte 1
D_bytes(3) = &HBB 'Byte 2
D_bytes(4) = &HCC 'Byte 3
D_bytes(5) = &H11 'Byte 4
D_bytes(6) = Packet_count 'Byte 5 will be increase every loop
Call W_register(6) 'Write 6 bytes to register
Waitms 2
Set Ce 'Set CE for a short moment to transmit the fifo buffer
Waitms 1 '
Reset Ce '
Waitms 100 'Some delay to read the output on the terminal, line can be removed for max. speed
W = 0 'Counter for time out
Do
If Irq = 0 Then
Call R_register(status , 1)
Temp = B_bytes(1) And &B01110000 'Mask the IRQ bits out the status byte
Select Case Temp 'Which IRQ occurs
Case Max_rt 'MAX_RT
Print "Maximum number of TX retries, Flussing the TX buffer now !"
D_bytes(1) = Flush_tx 'Flush the TX buffer
Call W_register(1)
D_bytes(1) = Write_reg + Status
D_bytes(2) = &B00010000 'Clear the MAX_RT IRQ bit
Call W_register(2)
Exit Do
Case Tx_ds 'TX_DS
Print "Packet " ; Packet_count ; " send and ACK received."
D_bytes(1) = Write_reg + Status
D_bytes(2) = &B00100000 'Clear the TX_DS IRQ bit
Call W_register(2)
Exit Do
Case Else 'Other IRQ ??
Print "Other irq " ; Bin(temp)
D_bytes(1) = Flush_tx 'Flush the TX buffer
Call W_register(1)
D_bytes(1) = Write_reg + Status
D_bytes(2) = &B00110000 'Clear both MAX_RT, TX_DS bits
Call W_register(2)
End Select
End If
Waitms 1 'Time out waiting for IRQ 1ms * 100
Incr W 'Increment W
If W > 100 Then 'Waited for 100ms
Print "No irq response from RF20L01 within 100ms"
Exit Do 'Exit the wait loop
End If
Loop
Loop
Return
'=== Sub routines ===
Sub W_register(byval C_bytes As Byte) 'Write register with SPI
Reset Ss 'Manual control SS pin, set SS low before shifting out the bytes
Spiout D_bytes(1) , C_bytes 'Shiftout the data bytes trough SPI , C_bytes is the amount bytes to be written
Set Ss 'Set SS high
End Sub
Sub R_register(byval Command As Byte , Byval C_bytes As Byte) As Byte 'C_bytes = Count_bytes, number off bytes to be read
Reset Ss 'Manual controle SS pin, set low before shifting in/out the bytes
Spiout Command , 1 'First shiftout the register to be read
Spiin B_bytes(1) , C_bytes 'Read back the bytes from SPI sended by nRF20L01
Set Ss 'Set SS back to high level
End Sub
Setup_rx: 'Setup for RX
D_bytes(1) = Write_reg + Rx_addr_p0 'RX adress for pipe0
D_bytes(2) = &H34
D_bytes(3) = &H43
D_bytes(4) = &H10
D_bytes(5) = &H10
D_bytes(6) = &H01
Call W_register(6) 'Send 6 bytes to SPI
D_bytes(1) = Write_reg + En_aa 'Enable auto ACK for pipe0
D_bytes(2) = &H01
Call W_register(2)
D_bytes(1) = Write_reg + En_rxaddr 'Enable RX adress for pipe0
D_bytes(2) = &H01
Call W_register(2)
D_bytes(1) = Write_reg + Rf_ch 'Set RF channel
D_bytes(2) = 40
Call W_register(2)
D_bytes(1) = Write_reg + Rx_pw_p0 'Set RX pload width for pipe0
D_bytes(2) = 5
Call W_register(2)
D_bytes(1) = Write_reg + Rf_setup 'Setup RF-> Output power 0dbm, datarate 2Mbps and LNA gain on
D_bytes(2) = &H0F
Call W_register(2)
D_bytes(1) = Write_reg + Config_nrf 'Setup CONFIG-> PRX=1(RX_device), PWR_UP=1, CRC 2bytes, Enable CRC
D_bytes(2) = &H0F
Call W_register(2)
Return
Setup_tx: 'Setup for TX
D_bytes(1) = Write_reg + Tx_addr 'TX adress
D_bytes(2) = &H34
D_bytes(3) = &H43
D_bytes(4) = &H10
D_bytes(5) = &H10
D_bytes(6) = &H01
Call W_register(6)
D_bytes(1) = Write_reg + Rx_addr_p0 'RX adress for pipe0
D_bytes(2) = &H34
D_bytes(3) = &H43
D_bytes(4) = &H10
D_bytes(5) = &H10
D_bytes(6) = &H01
Call W_register(6)
D_bytes(1) = Write_reg + En_aa 'Enable auto ACK for pipe0
D_bytes(2) = &H01
Call W_register(2)
D_bytes(1) = Write_reg + En_rxaddr 'Enable RX adress for pipe0
D_bytes(2) = &H01
Call W_register(2)
D_bytes(1) = Write_reg + Rf_ch 'Set RF channel
D_bytes(2) = 40
Call W_register(2)
D_bytes(1) = Write_reg + Rf_setup 'Setup RF-> Output power 0dbm, datarate 2Mbps and LNA gain on
D_bytes(2) = &H0F
Call W_register(2)
D_bytes(1) = Write_reg + Config_nrf 'Setup CONFIG-> PRX=0(TX_device), PWR_UP=1, CRC 2bytes, Enable CRC
D_bytes(2) = &H0E
Call W_register(2)
Return
Dump_registers: 'Dumps all nRF24L01 registers to the terminal, handy for debugging
Print "* Dump nRF24L01 Registers *"
Call R_register(config_nrf , 1)
Print "CONFIG : " ; Bin(b_bytes(1))
Call R_register(en_aa , 1)
Print "EN_AA : " ; Bin(b_bytes(1))
Call R_register(en_rxaddr , 1)
Print "EN_RXADDR : " ; Bin(b_bytes(1))
Call R_register(setup_aw , 1)
Print "SETUP_AW : " ; Bin(b_bytes(1))
Call R_register(setup_retr , 1)
Print "SETUP_RETR : " ; Bin(b_bytes(1))
Call R_register(rf_ch , 1)
Print "RF_CH : " ; B_bytes(1)
Call R_register(rf_setup , 1)
Print "RF_SETUP : " ; Bin(b_bytes(1))
Call R_register(status , 1)
Print "STATUS : " ; Bin(b_bytes(1))
Call R_register(observe_tx , 1)
Print "OBSERVE_TX : " ; Bin(b_bytes(1))
Call R_register(cd , 1)
Print "CD : " ; Bin(b_bytes(1))
Call R_register(rx_addr_p0 , 5)
Print "RX_ADDR_P0 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_addr_p1 , 5)
Print "RX_ADDR_P1 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_addr_p2 , 5)
Print "RX_ADDR_P2 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_addr_p3 , 5)
Print "RX_ADDR_P3 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_addr_p4 , 5)
Print "RX_ADDR_P4 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_addr_p5 , 5)
Print "RX_ADDR_P5 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(tx_addr , 5)
Print "TX_ADDR : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_pw_p0 , 5)
Print "RX_PW_P0 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_pw_p1 , 5)
Print "RX_PW_P1 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_pw_p2 , 5)
Print "RX_PW_P2 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_pw_p3 , 5)
Print "RX_PW_P3 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_pw_p4 , 5)
Print "RX_PW_P4 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(rx_pw_p5 , 5)
Print "RX_PW_P5 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5))
Call R_register(fifo_status , 1)
Print "FIFO_STATUS : " ; Bin(b_bytes(1))
Return
[/code:1:15ae7dfa46]
Tx UART out:
[code:1:15ae7dfa46]
Maximum number of TX retries, Flussing the TX buffer now !
Maximum number of TX retries, Flussing the TX buffer now !
Maximum number of TX retries, Flussing the TX buffer now !
Maximum number of TX retries, Flussing the TX buffer now !
Maximum number of TX retries, Flussing the TX buffer now !
[/code:1:15ae7dfa46]
Rx UART out:
[code:1:15ae7dfa46]
Pload : 0000000000
Pload : 0000000000
Pload : 0000000000
Pload : 0000000000
[/code:1:15ae7dfa46]
I used ATMega32(TQFP44 package).
I don't know what I should do? Please help me to solve this problem.
thank you.
[b:15ae7dfa46][color=red:15ae7dfa46](BASCOM-AVR version : 2.0.7.8 )[/b:15ae7dfa46][/color:15ae7dfa46]
↧
BASCOM-AVR : LoadLabel with part >64K : REPLY
I came across that thread before, but took a closer look. I still am not understanding it.
↧
BASCOM-AVR : Use software at second computer (home office) : NEWTOPIC
Hello,
My company uses one licence BASCOM AVR. Can I upgrade demo version on my private computer using this licence to work on company projects?
I mean: one licence, morning -first computer, evening-second computer.
Michał
[b:45ff1e7a14][color=red:45ff1e7a14](BASCOM-AVR version : 2.0.7.8 )[/b:45ff1e7a14][/color:45ff1e7a14]
↧
↧
BASCOM-AVR : Problem with NRF24L01P : REPLY
Excuse me
It's the soldering problem
↧
BASCOM-AVR : LoadLabel with part >64K : REPLY
Hi,
Something like this:
[code:1:c9a6b1e04d]
Dim Currentdb_a As Dword
Dim Ara(4) As Byte At Currentdb_a Overlay
Dim Currentdb_b As Dword
Dim Arb(4) As Byte At Currentdb_b Overlay
DBType = "US"
Gosub SetDatabase
WhatINeed = Lookupstr(MyIndex,CurrentDB_a)
Whatineed2 = Lookup(myindex , Currentdb_b)
' ---------
Setdatabase:
Select Case DBType
Case "US"
Restore Data_us_a
Ara(1) = Getreg(r8 )
Ara(2) = Getreg(r9 )
Ara(3) = Rampz
Restore Data_us_b
Arb(1) = Getreg(r8 )
Arb(2) = Getreg(r9 )
Arb(3) = Rampz
Case "EU"
Restore Data_eu_a
Ara(1) = Getreg(r8 )
Ara(2) = Getreg(r9 )
Ara(3) = Rampz
Restore Data_eu_b
Arb(1) = Getreg(r8 )
Arb(2) = Getreg(r9 )
Arb(3) = Rampz
End Select
Return
' ----------
Data_US_a:
DATA "123", "124", "125", "126"
DATA "127", "128", "129", "130"
Data_US_b:
DATA 131, 132, 133, 135
DATA 137, 139, 140, 141
Data_EU_a:
DATA "142", "144", "145", "146"
DATA "148", "150", "151", "152"
Data_EU_b:
DATA 155, 156, 158, 160
Data 166 , 167 , 168 , 170
[/code:1:c9a6b1e04d]
↧
BASCOM-AVR : LoadLabel with part >64K : REPLY
Ahhh, I understand. Will try it out. Thanks!
↧
BASCOM-AVR : Problem with NRF24L01P : REPLY
Thanks for sharing the solution.
If you ran in more problems [b:00966d0944]Gosub Dump_registers[/b:00966d0944] to printout some more info.
↧
↧
BASCOM-AVR : Use software at second computer (home office) : REPLY
sure. but as soon you leave the company and someone else is going to use that PC too, you would need another lic.
↧
BASCOM-AVR : Timer-Interrupts : NEWTOPIC
This program is intended to provide the basics for interrupt programming.
Interrupts interrupt upon the occurrence of the conditions the program flow to branch, called the interrupt service routine, abbreviated in an associated subroutine: ISR
I made a simple program because PORTD.0 and PORTD.1 not blink when push the button PORTC.0? Chece and all the program and compiles without error.
[code:1:f1ecc97f99]
$regfile = "m16adef.dat"
$Crystal=4000000
$hwstack=40
$swstack=16
$framesize=32
Config Portd = Output
Config Porta = Output
Config Portc = Input
Dim N As Word
Dim Boton As Bit
Dim Zs As Bit
Dim Bz As Byte
Dim Bz1 As Byte
Const On = 0
Const Off = 1
Config Timer0 = Timer , Prescale = 64
On Timer0 T0_isr
Enable Timer0
Enable Interrupts
Portd = &B11111111
Do
Boton = Pinc.0
If Boton = On Then Gosub Blinkeando Else Portd.0 = Off
Zs = 0
Loop
Blinkeando:
If Zs = 1 Then
Incr Bz
If Bz > 50 Then
Bz = 0
End If
If Bz = 1 Then Portd.0 = 0
If Bz = 4 Then Portd.0 = 1
Incr Bz1
If Bz1 > 55 Then
Bz1 = 0
End If
If Bz1 = 1 Then Portd.1 = 0
If Bz1 = 5 Then Portd.1 = 1
End If
Return
T0_isr:
Incr N
If N >= 50 Then
Toggle Porta.0
N = 0
End If
Return
End[/code:1:f1ecc97f99]
[b:f1ecc97f99][color=red:f1ecc97f99](BASCOM-AVR version : 2.0.7.8 )[/b:f1ecc97f99][/color:f1ecc97f99]
↧
BASCOM-AVR Old versions : Timer-Interrupts : REPLY
Depends how you connected your button.
If you connected it between pinc.0 and gnd you need a pull-up resistor to vcc.
You can enable this with
[code:1:9de811a61c]portc.0 = 1[/code:1:9de811a61c]
Btw I think [b:9de811a61c]On[/b:9de811a61c] and [b:9de811a61c]Off[/b:9de811a61c] are reserved words in Bascom, better choose other alias.
↧
BASCOM-AVR : ISP programming problem : NEWTOPIC
Hi,
with a circuit I have a problem during the ISP programming, the programmer ATMEL AVRISP mkII starts flashing red LED and the microprocessor is not programmed.
If I disconnect the display everything goes OK.
I also tried it with another display always with T6963C chipset, but I have the same problem ...
I have attached the circuit diagram ...
Somebody help me solve the problem thanks.
[b:6d268b06be][color=red:6d268b06be](BASCOM-AVR version : 2.0.7.8 )[/b:6d268b06be][/color:6d268b06be]
↧
↧
BASCOM-AVR : ISP programming problem : REPLY
The CE pin of T6963C, please pull up resistor of 10K ohm - 47K ohm.
↧
BASCOM-AVR : ISP programming problem : REPLY
Connect a pulldown resistor to PC3.
As soon the controller gets into reset, its pins become high impedance and so the pulldown will put the LCD in reset condition too.
Which should disconnect the data pins from the ISP pins, which is the obvious problem here, as the LCD-controller pins in random state block the ISP.
If above won't work, then directly connect display reset to ATM32 reset.
↧
BASCOM-AVR : ISP programming problem : REPLY
Good solution... problem solved thanks . =D>
[quote:4cfef57403]The CE pin of T6963C, please pull up resistor of 10K ohm - 47K ohm.[/quote:4cfef57403]
↧