View previous topic :: View next topic |
Author |
Message |
Dave
Joined: 05 Feb 2005 Posts: 314 Location: OR
|
Posted: Thu Jul 31, 2014 3:21 am Post subject: data problem |
|
|
Hello All,
This code will run in your simulater. Please try it and help me understand why it does not work
like I think it should.
The sub RFM24_Configure should step through all the data statments sending config data to my RFM24W.
The first read data is the length of the data set to be sent to the rfm24. Then data set is sent. Then the next read after that is the length of the next set...
It is suppose to read through ALL the data until the length is zero.
The problem is it stops before reaching the end of the data. You will have to run it to see what I'm trying to explain.
I've commented out the hardware parts for the sim but the problem still shows up.
Code: | $regfile = "m168def.dat"
$crystal = 8000000
$baud = 38400
$hwstack = 100
$swstack = 100
$framesize = 100
CONFIG SUBMODE = NEW
sub RFM24_Configure()
local b_dat as byte
local b_Length as byte
local b_n as byte
local b_temp as byte
restore CONFIGURATION_COMMANDS
read b_Length
while b_Length > 0
'reset rfm24_Nsel
print
print "L1 ";b_Length
for b_n = 1 to b_Length
read b_dat
'spiout b_dat,1
print "D ";hex(b_dat)
next
'set rfm24_Nsel
'b_temp=Api_WaitforCTS()
read b_Length
print "L2 ";b_Length
wend
print "end config ";b_Length
end sub
rfm24_configure
do
loop
end
CONFIGURATION_COMMANDS:
' Command: RF_POWER_UP
' Description: Command to power-up the device and select the operational mode and functionality.
RF_POWER_UP:
data 7
data &h02, &h01, &h00, &h01, &hC9, &hC3, &h80
' Command: RF_GPIO_PIN_CFG
' Description: Configures the GPIO pins.
RF_GPIO_PIN_CFG:
data 8
data &h13, &h61, &h00, &h60, &h00, &h40, &h00, &h20
' Set properties: RF_GLOBAL_XO_TUNE_1
' Number of properties: 1
' Group ID: &h00
' Start ID: &h00
' Default values: &h40,
' Descriptions:
' GLOBAL_XO_TUNE - Configure the internal capacitor frequency tuning bank for the crystal oscillator.
RF_GLOBAL_XO_TUNE_1:
data 5
data &h11, &h00, &h01, &h00, &h52
' Set properties: RF_INT_CTL_ENABLE_2
' Number of properties: 2
' Group ID: &h01
' Start ID: &h00
' Default values: &h04, &h00,
' Descriptions:
' INT_CTL_ENABLE - This property provides for global enabling of the three interrupt groups (Chip, Modem and Packet Handler)
' in order to generate HW interrupts at the NIRQ pin.
' INT_CTL_PH_ENABLE - Enable individual interrupt sources within the Packet Handler Interrupt Group to generate a HW interrupt
' on the NIRQ output pin.
RF_INT_CTL_ENABLE_2:
data 6
data &h11, &h01, &h02, &h00, &h01, &h30
' Set properties: RF_FRR_CTL_A_MODE_4
' Number of properties: 4
' Group ID: &h02
' Start ID: &h00
' Default values: &h01, &h02, &h09, &h00,
' Descriptions:
' FRR_CTL_A_MODE - Fast Response Register A Configuration.
' FRR_CTL_B_MODE - Fast Response Register B Configuration.
' FRR_CTL_C_MODE - Fast Response Register C Configuration.
' FRR_CTL_D_MODE - Fast Response Register D Configuration.
RF_FRR_CTL_A_MODE_4:
data 8
data &h11, &h02, &h04, &h00, &h00, &h00, &h00, &h00
' Set properties: RF_PREAMBLE_TX_LENGTH_9
' Number of properties: 9
' Group ID: &h10
' Start ID: &h00
' Default values: &h08, &h14, &h00, &h0F, &h21, &h00, &h00, &h00, &h00,
' Descriptions:
' PREAMBLE_TX_LENGTH - Configure length of TX Preamble.
' PREAMBLE_CONFIG_STD_1 - Configuration of reception of a packet with a Standard Preamble pattern.
' PREAMBLE_CONFIG_NSTD - Configuration of transmission/reception of a packet with a Non-Standard Preamble pattern.
' PREAMBLE_CONFIG_STD_2 - Configuration of timeout periods during reception of a packet with Standard Preamble pattern.
' PREAMBLE_CONFIG - General configuration bits for the Preamble field.
' PREAMBLE_PATTERN_31_24 - Configuration of the bit values describing a Non-Standard Preamble pattern.
' PREAMBLE_PATTERN_23_16 - Configuration of the bit values describing a Non-Standard Preamble pattern.
' PREAMBLE_PATTERN_15_8 - Configuration of the bit values describing a Non-Standard Preamble pattern.
' PREAMBLE_PATTERN_7_0 - Configuration of the bit values describing a Non-Standard Preamble pattern.
RF_PREAMBLE_TX_LENGTH_9:
data 13
data &h11, &h10, &h09, &h00, &h08, &h14, &h00, &h0F, &h31, &h00, &h00, &h00, &h00
stop_config:
data 0 'length of zero stops the configuation.
|
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Thu Jul 31, 2014 4:47 am Post subject: |
|
|
Hi,
I've not looked at your code too closley but I'm doing something similar for my RFM73 module. Maybe you can make use of the code:-
Code: |
Sub Setup_radiomodule()
'Function : Setup radio module
'Author : Ian Dobson
'Inputs : None.
'Outputs : None
'Limitations : The data structure with the data to be written needs to be selected
'Date : 19.1.2014
Do
Read Temp_byte1
If Temp_byte1 = 0 Then
Exit Do
End If
For Temp_byte = 1 To Temp_byte1
Read D_bytes(temp_byte)
Next Temp_byte
If D_bytes(1) = Rx_addr_p0 Then
D_bytes(1) = Address
End If
D_bytes(1) = D_bytes(1) + Write_reg
Call Write_register(temp_byte1)
Loop
End Sub
'--- Data for receiver radio module -------------------------------------------
Rx_structure:
Data 2 , Setup_aw , &B00000001 '3bit address
Data 4 , Rx_addr_p0 , &H01 , &H42 , &H24 'RX adress for pipe0
Data 2 , En_aa , &H01 'Enable auto ACK for pipe0
Data 2 , En_rxaddr , &H01 'Enable RX adress for pipe0
Data 2 , Rf_ch , 99 'Set RF channel
Data 2 , Rx_pw_p0 , 3 'Set RX pload width for pipe0
Data 2 , Rf_setup , &B00000111 'Setup RF-> Output power 5dbm, datarate 1Mbps and LNA gain on
Data 2 , Config_nrf , &B00001011 'Setup CONFIG-> PRX=1(RX_device), PWR_UP=1, CRC 1bytes, Enable CRC
Data 0 'end of data
|
The data structure is Number of Bytes, Register Name, X Bytes of data.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
Dave
Joined: 05 Feb 2005 Posts: 314 Location: OR
|
Posted: Thu Jul 31, 2014 5:13 am Post subject: |
|
|
Thanks Ian,
We are doing about the same thing.
My code stops unexpected after the second data set. The next length in the next data set is 5 but the read returns 0.
I should have commented the lengths in the data. The lengths are the data that is not in hex.
I still don't know what the problem is.. |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Thu Jul 31, 2014 5:25 am Post subject: |
|
|
Hi,
The 4th Byte in your data is 0. Could it be that the code is seeing that and stopping?
As I said I've not looked at your code too much, and I have to leave for work now...
Just try single stepping through the code and see where it stops (start Simulator, set breakpoint at the start of the Setup Routine and use F8 to execute each line of code).
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
Dave
Joined: 05 Feb 2005 Posts: 314 Location: OR
|
Posted: Thu Jul 31, 2014 5:30 am Post subject: |
|
|
Progress!
I just removed some of the labels in the data and now the program reads data correctly till it comes to a label then stops again.
Maybe there is something wrong with my labels. To long? I'll keep trying. |
|
Back to top |
|
|
Dave
Joined: 05 Feb 2005 Posts: 314 Location: OR
|
Posted: Thu Jul 31, 2014 5:44 am Post subject: |
|
|
Ian
Thanks again, I have single stepped and it makes no sense.
I think it's a problem for Mark to look at.
If I put in any labels in the data the read statement breaks.
I hope Mark is reading this because it's going to be hard to explain in an email. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Jul 31, 2014 9:11 am Post subject: |
|
|
when you put a label into the code the data need to be aligned. otherwise a RESTORE on a label will not work.
For example :
sample 1
abc:
data 1
def:
data 2
sample 2
abc:
data 1
data 2
the second sample will combine the 2 bytes into a word and stores it in the word address of the flash.
the first sample will store the 1 and a zero byte because of the 'def' label. then it stores a 2 and also a zero so the data ends up in 2 words. while in sample 2, the data ends up in 1 word. _________________ Mark |
|
Back to top |
|
|
Dave
Joined: 05 Feb 2005 Posts: 314 Location: OR
|
Posted: Thu Jul 31, 2014 3:46 pm Post subject: |
|
|
Thanks Mark
I'm glad it's not a bug in bascom. A warning by the compiler or in Language Fundamentals would be a good improvement.
Here is my solution for now.
if the last length is an even number add a second read for the next length.
Code: | while b_Length > 0
b_temp = b_Length mod 2 '<--- b_temp = 0 or 1 for even or odd number.
'reset rfm24_Nsel
print
print "L1 ";b_Length
for b_n = 1 to b_Length
read b_dat
'spiout b_dat,1
print "D ";hex(b_dat)
next
'set rfm24_Nsel
'b_temp=Api_WaitforCTS()
read b_Length
if b_temp=0 then read b_Length '<--- add an extra read needed for even lengths.
print "L2 ";b_Length
wend |
|
|
Back to top |
|
|
Dave
Joined: 05 Feb 2005 Posts: 314 Location: OR
|
Posted: Thu Jul 31, 2014 4:12 pm Post subject: |
|
|
I added dummy data for word alinement. This works I think...
Code: | $regfile = "m168def.dat"
$crystal = 8000000
$baud = 38400
$hwstack = 100
$swstack = 100
$framesize = 100
CONFIG SUBMODE = NEW
sub RFM24_Configure()
local b_dat as byte
local b_Length as byte
local b_n as byte
local b_temp as byte
restore CONFIGURATION_COMMANDS
read b_Length
while b_Length > 0
b_temp = b_Length mod 2 '<--- b_temp = 0 or 1 for even or odd number.
'reset rfm24_Nsel
print
print "L1 ";b_Length
for b_n = 1 to b_Length
read b_dat
'spiout b_dat,1
print "D ";hex(b_dat)
next
'set rfm24_Nsel
'b_temp=Api_WaitforCTS()
read b_Length
print "L2 ";b_Length
if b_temp=0 then
read b_Length '<--- add an extra read needed for even lengths of last data set.
print "L3 ";b_Length
end if
wend
print "end config ";b_Length
end sub
rfm24_configure
do
loop
end
CONFIGURATION_COMMANDS:
RF_POWER_UP:
data 7
data &h02, &h01, &h00, &h01, &hC9, &hC3, &h80
RF_GPIO_PIN_CFG:
data 8
data &h13, &h61, &h00, &h60, &h00, &h40, &h00, &h20
data 0 'dummy data for word alinement.
RF_GLOBAL_XO_TUNE_1:
data 5
data &h11, &h00, &h01, &h00, &h52
RF_INT_CTL_ENABLE_2:
data 6
data &h11, &h01, &h02, &h00, &h01, &h30
data 0 'dummy data for word alinement.
RF_FRR_CTL_A_MODE_4:
data 8
data &h11, &h02, &h04, &h00, &h00, &h00, &h00, &h00
data 0 'dummy data for word alinement.
RF_PREAMBLE_TX_LENGTH_9:
data 13
data &h11, &h10, &h09, &h00, &h08, &h14, &h00, &h0F, &h31, &h00, &h00, &h00, &h00
stop_config:
data 0 'length of zero stops the configuration. |
|
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Jul 31, 2014 7:13 pm Post subject: |
|
|
albertsm wrote: | when you put a label into the code the data need to be aligned. otherwise a RESTORE on a label will not work. |
With all due respect
I see no reason, why there should be only access to aligned bytes.
The compiler knows, whether an even or odd flash byte address is accessed. The Restore command accepts no variable, so everything is set and can be done at compile time.
In case a Data-label points to an odd byte address, the Z-pointer can be set to the basic word address, then a dummy LPM read is issued and voila, c'est fait.
I'm a friend of large data segments, which can be either read sequentially from start till end, or read segmented by labels.
Padding bytes are therefore unnecessary and annoying. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Jul 31, 2014 8:10 pm Post subject: |
|
|
it is a simple basic rule : a label is equivalent to an address and in the AVR we have word addresses. you can use a label for goto and gosub as well. So per definition, a label means that code will be on a word address.
And second, there is one pass which means that at time of RESTORE the compiler does not even know about the data.
If you want data without alignment simply do not insert labels. _________________ Mark |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Jul 31, 2014 8:53 pm Post subject: |
|
|
I do not care that much about basic rules, if I would have, I'd missed some interesting solutions.
From the logic POV I see no reason, why a label could not be on an uneven word address, all basic rules and conventions aside.
If one would address labels by byte, the compiler would not need to know, what it accesses. The LPM opcode, which is used by subsequent reads following a restore, is prepared for byte exact reads, see LPM in Atmel's instruction set manual. Remember, we still have an 8bit CPU here, and as well it uses word-organized program code, it still crunches data byte per byte.
It may be, that all Bascom's internal mechanics are based on word addresses, but that doesn't mean I need to stop thinking about what's basically possible or beneficial |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Jul 31, 2014 10:53 pm Post subject: |
|
|
i did not say a label can not be an uneven word address. i said the address is always a word. which means it uses 2 bytes. this because all instructions use words (2 bytes). Some uses even 2 words. I know you know all this stuff but for completeness :
address 0:
byte 1 , byte 2 ; an instruction will use at least 2 bytes
address 1:
byte 3, byte 4
address 2:
byte 5, byte 6
when you do a jump/call you can only do so to a word address. you can not jump into the middle of it. that is why a label always is aligned to a word. _________________ Mark |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Aug 01, 2014 1:21 am Post subject: |
|
|
Sure, word alignement is important within the code segment, but this is all about a data segment. Also sure, data labels do not look different to code labels.
A jump to an uneven data label would thus fail, but I can't think of many uses, why one would like jump to or execute data. If a data segment is placed within code, padding needs to be done, but only at the end of the data segment, so following code is aligned again.
Still I do not see the need of word aligned data labels within a data segment, other than the ease and consistency to treat all labels the same, no matter if code or data segment. |
|
Back to top |
|
|
TSEYFARTH
Joined: 01 Jul 2006 Posts: 1054
|
Posted: Sat Aug 02, 2014 5:49 am Post subject: |
|
|
Hello All,
Can 'Data' be configured as a 2 o3 dimensional structure, with varying lengths of elements like this C code - which consists of constants and a structure:
#define RF_POWER_UP 0x02, 0x01, 0x01, 0x01, 0xC9, 0xC3, 0x80
#define RF_GPIO_PIN_CFG 0x13, 0x5C, 0x53, 0x5B, 0x51, 0x00, 0x00
#define RADIO_CONFIGURATION_DATA_ARRAY { \
0x07, RF_POWER_UP, \
0x07, RF_GPIO_PIN_CFG, \
0x00 \
}
const u8 RFM24_CONFIGURATION_DATA[]=RADIO_CONFIGURATION_DATA_ARRAY;
Maybe the better question is, can Data be given a unique name?
Ians code
Quote: |
Rx_structure:
Data 2 , Setup_aw , &B00000001 '3bit address
Data 4 , Rx_addr_p0 , &H01 , &H42 , &H24 'RX adress for pipe0
Data 2 , En_aa , &H01 'Enable auto ACK for pipe0
Data 2 , En_rxaddr , &H01 'Enable RX adress for pipe0
Data 2 , Rf_ch , 99 'Set RF channel
Data 2 , Rx_pw_p0 , 3 'Set RX pload width for pipe0
Data 2 , Rf_setup , &B00000111 'Setup RF-> Output power 5dbm, datarate 1Mbps and LNA gain on
Data 2 , Config_nrf , &B00001011 'Setup CONFIG-> PRX=1(RX_device), PWR_UP=1, CRC 1bytes, Enable CRC
Data 0 'end of data
|
Is really similar to what I was thinking, except giving the word "Data" a unique name. Is this possible?
Tim |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|