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 Heidi,
Thank you for your answers.
So the difference is that the ´[channel_id]´ is the index into the channel array (AIN1 has index 0, AIN2 has index 1 etc.) and ´[input_positive]´ (which is the channel input) is the specific analog input, so AIN1 and AIN2.
If channel_id = 0 i.e. index zero into the channel array gets AIN1 then what is the index for channel AIN0?
I have not finished reading your answers but I thought I ask this question in case it affects my understanding of the remainder of your answer.
Kind regards
Mohamed
Another thing I wanted to clarify by using the custom binding of the sample as an example, is this line:
Fullscreen1io-channels = <&adc 0>, <&adc 1>;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXio-channels = <&adc 0>, <&adc 1>;As you can see, the io-channels are ´[&adc 0]´ and ´[&adc 1]´ which maps the ADC peripheral to channel 0 and 1. This just maps the ADC node to the analog input of channel 0 and the analog input of channel 1, which is AIN1 and AIN2, which then maps to GPIO pin P0.04 and P0.05 on the PDK, according to this table describing the mapping of analog pins on the nRF5340 PDK.
According to the PCA10095 schematics of the nRF5340 PDK (nRF5340-QKAA) pin 4 on P0.04 is AIN0 not AIN1.
I have already raised this issue with Martin Lesund about three weeks ago and he said he will get this corrected. There seems to be some discrepancy between the user guide and the schematics. The latter is correct.
So, this means channel_id = 0 i.e. index zero into the channel array points to AIN0.
Kind regards
Mohamed
So, this means channel_id = 0 i.e. index zero into the channel array points to AIN0.
Since it seems we have the channel_id index offset by one in the nRF5340PDK, does it mean the examples referred to will not work as expected?
According to the PCA10095_schematics of the nRF5340PDK pin P0.28 is AIN7. So, I connected a potentiometer to pins: P0.28, VDD, GND and tried to run the light intensity controller example but the adc did not work with this configuration code.
#define ADC_1ST_CHANNEL_ID 7
#define ADC_1ST_CHANNEL_INPUT NRF_SAADC_INPUT_AIN7
So, I looked closely to pin P0.28 on the back of the pdk board and realised that P0.28 is actually labelled (A2). So, I changed the config to,
#define ADC_1ST_CHANNEL_ID 2
#define ADC_1ST_CHANNEL_INPUT NRF_SAADC_INPUT_AIN2
and Bingo! it works. So, it seems that for the nRF5340PDK the values used for ADC_1ST_CHANNEL_ID and ADC_1ST_CHANNEL_INPUT must the same. Any comments?
Kind regards
Mohamed
Hi!
You know what, I misunderstood the description of channel_id. Sorry about that.
At a closer look: "This value primarily identifies the channel within the ADC API". So the value of the channel_id does not matter (in the range of 0 to 7) as long as it is used consistently to identify that channel. This explains why channel ID 0 is used for AIN0 and channel 2 is used for AIN2, here.
My mistake, sorry for the confusion! There is no channel id offset and the sample should work as expected.
Yes, the table I linked to is apparently incorrect, so this is the correct pin mapping.
AIN0 | P0.04 |
AIN1 | P0.05 |
AIN2 | P0.06 |
AIN3 | P0.07 |
AIN4 | P0.25 |
AIN5 | P0.26 |
AIN6 | P0.27 |
AIN7 | P0.28 |
Learner said:Bingo! it works.
Did it work with the analog device plugged into GPIO pin 28 or pin 6?
If it was pin 28, could you attach the file with the path build_folder/zephyr/zephyr.dts just so I can confirm this?
Again, sorry for the confusion.
Best regards,
Heidi
Hi Heidi,
No problem, we are all learning in the process.
At a closer look: "This value primarily identifies the channel within the ADC API". So the value of the channel_id does not matter (in the range of 0 to 7) as long as it is used consistently to identify that channel. This explains why channel ID 0 is used for AIN0 and channel 2 is used for AIN2, here.
I am not sure I understand what you are trying to say here.
I understand the need to configure which analog pin is being used but I am still not clear on which one of these two macros is doing this job. If as you said it is ADC_1ST_CHANNEL_INPUT then why is ADC_1ST_CHANNEL_ID needed?
The best way to understand what channel_id does is to see where it is used in the driver code. There is a driver function called channel_setup but I could not locate it. Could you please ask your colleagues developers to point us where in the driver code this function that uses channel_id and channel_input is.
Thank you.
Kind regards
Mohamed
Hi Heidi,
No problem, we are all learning in the process.
At a closer look: "This value primarily identifies the channel within the ADC API". So the value of the channel_id does not matter (in the range of 0 to 7) as long as it is used consistently to identify that channel. This explains why channel ID 0 is used for AIN0 and channel 2 is used for AIN2, here.
I am not sure I understand what you are trying to say here.
I understand the need to configure which analog pin is being used but I am still not clear on which one of these two macros is doing this job. If as you said it is ADC_1ST_CHANNEL_INPUT then why is ADC_1ST_CHANNEL_ID needed?
The best way to understand what channel_id does is to see where it is used in the driver code. There is a driver function called channel_setup but I could not locate it. Could you please ask your colleagues developers to point us where in the driver code this function that uses channel_id and channel_input is.
Thank you.
Kind regards
Mohamed