I can see in Segger Embedded Studio v4.52 under the Build Tab, there are two methods to build the project.
1- Build > Build zephyr/zephyr.elf
2- Build > Build solution
What is the difference between the two methods?
Kind regards
I can see in Segger Embedded Studio v4.52 under the Build Tab, there are two methods to build the project.
1- Build > Build zephyr/zephyr.elf
2- Build > Build solution
What is the difference between the two methods?
Kind regards
Hi again!
So, first of all, to answer your questions about SPI:
You are right, I did not catch that part. I have sent a message to the Nordic developer that has written this, but since they are based in LA I won't have an answer on this until tomorrow.
I just received an answer about this.
"An index representing the peripheral’s chip select line number. (If there is no chip select line, 0 is used.)"
The spi1 node has a cs-gpios property, which means that the unit addresses for node a and b (0 and 1 respectively) are indexes into the cs-gpios array (an index representing the peripheral's chip select line number). The spi1 node has no cs-gpios, so node c has no chip select configured in the device tree, and therefore its unit address is left at 0 (if there is no chip select line, 0 is used).
In all your overlay examples you're still instantiating the ADC peripheral, which we don't want to do.
This is the template you want to follow:
/ { n: node { compatible = " "; io-channels = <&adc 4>; label = "AIN_0"; }; };
The forward slash indicates the root node and is very important to include.
To include multiple ADC io-channels, just refer to the adc-node each time like this (not &adc5 and &adc7):
io-channels = <&adc 26>, <&adc 28>;
and if you want to use a different compatible property for the two nodes, you need to create two separate nodes like this:
/ { n: node_a { compatible = " "; io-channels = <&adc 26>; label = "AIN_5"; }; n: node_b { compatible = " "; io-channels = <&adc 28>; label = "AIN_7"; }; };
For you question about voltage-divider
The lower leg is not a resistor, but the other one is a resistor? Or are you using a capacitive divider where both elements are capacitors?
For your binding question, yes this is the correct way to do it, using the label you defined in the node.
adc_dev_5 = device_get_binding("AIN_5");
adc_dev_7 = device_get_binding("AIN_7");
To do the binding for the two analog inputs, this is how to do it for AIN_5 and AIN_7 respectively.
device_get_binding(DT_IO_CHANNELS_LABEL_BY_IDX(DT_NODELABEL(n),0))
device_get_binding(DT_IO_CHANNELS_LABEL_BY_IDX(DT_NODELABEL(n),1))
Best regards,
Heidi
If I include in main.c
#include <hal/nrf_saadc.h>
and use this overlay file
&pwm0 {
ch0-pin = < 29 >;
};
/ {
n: node {
compatible = "voltage-divider";
io-channels = <&adc 4>;
label = "AIN_0";
};
};
then I get a different error,
devicetree error: 'output-ohms' is marked as required in 'properties:' in C:/Zypher/v1.3.0/zephyr/dts/bindings\adc\voltage-divider.yaml, but does not appear in <Node /node in 'nrf5340pdk_nrf5340_cpuapp.dts.pre.tmp'>
This suggests I need to add these two lines to the device tree fragment in the overlay file
output-ohms = <???>;
full-ohms = <(??? + ???)>;
But I am not sure if the "voltage-divider" works with an R-C circuit?
Finally, get_binding() does not bind AIN_0, it can only bind ADC_0.
Are you sure the label line can have something other than ADC_0?
Maybe I Should make changes to the source code (the light intensity controller example) in main.c when I am using the overlay file ?
Kind regards
Mohamed
Hi!
So according to the analog inputs and channels page for the nRF5340, there are eight analog input channels that can be configured CH[n] (n=0, 1, .., 7).
There are also eight analog inputs available (AIN0, AIN1, ... AIN7) and VDD and VDDHDIV5.
So the channel_id refers to one of the eight analog input channels and the channel_input refers to an analog input. That is the difference.
There are 8 identical analog input channels and you can use whichever one you want and you can configure that channel with any analog input you want. They are not "connected" as I initially thought, where channel 0 uses AIN0 and so forth.
If it helps you understand better, here is how the channel_id is used in the code.
So the function adc_nrfx_channel_setup(const struct device *dev, const struct adc_channel_cfg *channel_cfg)
is called, where channel_id is one of the properties in the adc_channel_cfg struct.
Then, in this function, the channel_id is passed to nrf_saadc_channel_init(), here. If you take a look at the function definition, you can see the channel ID is being used the select the correct CH[n].CONFIG register to add all the configurations.
p_reg->CH[channel].CONFIG =
The positive input isn't set until the start_read() function is called. Then the function nrf_saadc_channel_pos_input_set() is called here. If we take a look at this function definition:
p_reg->CH[channel].PSELP = pselp; where NRF_SAADC_Type * p_reg = NRF_SAADC uint8_t channel = ADC_1ST_CHANNEL_ID nrf_saadc_input_t pselp = ADC_1ST_CHANNEL_INPUT
we can see that it uses the channel ID to the specific channel to be associated with the analog input passed to the function (ADC_1ST_CHANNEL_ID).
So for instance you can set NRFSAADC->CH[0].PSELP = NRF_SAADC_INPUT_AIN7 without a problem.
Learner said:If as you said it is ADC_1ST_CHANNEL_INPUT then why is ADC_1ST_CHANNEL_ID needed?
So to answer this question it's because the channel ID specifies which of the analog input channels you are referring to and is used with the register CH[channel_id].PSELP and CH[channel_id].CONFIG. And the channel input defines which analog input to "attach" to that channel.
So CH[CHANNEL_ID].PSELP = CHANNEL_INPUT.
Learner said:So, it seems that for the nRF5340PDK the values used for ADC_1ST_CHANNEL_ID and ADC_1ST_CHANNEL_INPUT must the same. Any
No, they do not need to be the same. You do however need to be connected to the correct GPIO pin.
Learner said:So, I looked closely to pin P0.28 on the back of the pdk board and realised that P0.28 is actually labelled (A2)
Those labels are just the arduino naming and don't correspond to the analog inputs.
It also looks like the printing on back of the board and the front of the board don't match up.
The front of the board has the correct labeling, so if you are plugged into the pin with the P0.08 label on the back, you are actually connected to P0.06 which is AIN2. So at least that mystery is solved!
Also, on the nRF5340 PDK GPIO P0.28 (AIN7) is also used for LED1. To be able to use AIN7, you will need to cut SB5 on the board, see here.
Best regards,
Heidi
Hi Heidi,
Did it work with the analog device plugged into GPIO pin 28 or pin 6?
Apologies, it was NOT P0.28 that I am connecting the pot to but P0.06.
The reason I got confused is because the labelling on the top and bottom of the nRF5340pdk board is different. I looked on the bottom side where the pot was soldered on and there it says P0.28 (A2). This morning, by accident, I was looking at the top of the pdk board and noticed there was a pin labelled P0.06 which also happens to be the pin the pot is connected to. So, I think P0.28 (A2) is for another board not the nRF5340PDK.
Kind regards
Mohamed
Hi Heidi,
Thank you. It is much clearer now.
p_reg->CH[channel].PSELP = pselp;
where
NRF_SAADC_Type * p_reg = NRF_SAADC
uint8_t channel = ADC_1ST_CHANNEL_ID
nrf_saadc_input_t pselp = ADC_1ST_CHANNEL_ID
I think you meant to say nrf_saadc_input_t pselp = ADC_1ST_CHANNEL_INPUT. Right?
Kind regards
Mohamed
Yes absolutely! I have changed it now. :)
Thank you Heidi.
I would like to 'Verify Answer' but there bits bits of information spread over multiple posts. One way to do this would be to add the bits of missing information to the post that has most of the correct info. Please let me know and I will Verify.
Kind regards
Mohamed
Thank you Heidi.
I would like to 'Verify Answer' but there bits bits of information spread over multiple posts. One way to do this would be to add the bits of missing information to the post that has most of the correct info. Please let me know and I will Verify.
Kind regards
Mohamed