SPI Documentation

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

SPI Documentation

Nikolas Becker
Hi guys,

I'm working now with my ethernut5 and the TCP/IP-functionality is just so nice working out of the box, very happy with it.

Now I need to read data from several ADCs via SPI. And here comes my problem: where can I find some documentation for the SPI device driver?

In the Nut/OS Software manual
http://www.ethernut.de/pdf/enswm28e.pdf
 there are some lines regarding SPI on page 45, suggesting the use of NutRegisterSpiDevice(), but not much more.

In the Nut/OS wiki, I found this article:
http://www.ethernut.de/nutwiki/index.php/Documents/NTN-6_SPI
Which gives some examples for using the SPI and are very similar to the usage here:
http://www.ethernut.de/nutwiki/index.php/SPI
So I tried this:

#define NUMBER_OF_CHANNELS 4
#define ADC_CONV_PIN 3
#define ADC_CONV_PORT NUTGPIO_PORTB

NUTSPINODE adc_node = {&spiBus0At91, NULL, 45158500, 0, (NUMBER_OF_CHANNELS*32), 0};
volatile uint32_t write_buffer[NUMBER_OF_CHANNELS];
volatile uint32_t read_buffer[NUMBER_OF_CHANNELS];

static int ADC_init(NUTSPINODE *node)
{
   int rc;
   GpioPinSetHigh(ADC_CONV_PORT, ADC_CONV_PIN);
   GpioPinConfigSet(ADC_CONV_PORT, ADC_CONV_PIN, GPIO_CFG_OUTPUT);
   NutSleep(100);
   rc = (*node->node_bus->bus_initnode) (node);
   if (rc == 0)
           NutEventPost(&node->node_bus->bus_mutex);
   return rc;
}

int ADC_transmit(uint8_t *write, uint8_t *read, int len)
{
        int rc;
        GpioPinSetLow(ADC_CONV_PORT, ADC_CONV_PIN);
        rc = (*spiBus0At91.bus_alloc) (&adc_node, 1000);
        if (rc == 0)
                rc = (*spiBus0At91.bus_transfer) (&adc_node, write, read, len);
        GpioPinSetHigh(ADC_CONV_PORT, ADC_CONV_PIN);
        (*spiBus0At91.bus_release) (&adc_node);
        return rc;
}

By simply calling ADC_init(&adc_node) and then ADC_transmit((uint8_t*)write_buffer,(uint8_t*)read_buffer,32*NUMBER_OF_CHANNELS), the program fully stops at the spiBus0At91.bus_transfer - call.

In the Doxygen-API-Documentation
http://ethernut.de/api-beta/struct___n_u_t_s_p_i_b_u_s.html#a928fd4b51cada2b0a159d79551495551
There are no information given regarding usage of the functions.

Is there any source where I can further read?

Best regards,
    Nikolas


_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion
Reply | Threaded
Open this post in threaded view
|

Re: SPI Documentation

Uwe Bonnes
Nikolas Becker writes:

> Hi guys,
>
> I'm working now with my ethernut5 and the TCP/IP-functionality is just so nice working out of the box, very happy with it.
>
> Now I need to read data from several ADCs via SPI. And here comes my problem: where can I find some documentation for the SPI device driver?
>
> In the Nut/OS Software manual
> http://www.ethernut.de/pdf/enswm28e.pdf
>  there are some lines regarding SPI on page 45, suggesting the use of NutRegisterSpiDevice(), but not much more.
>
> In the Nut/OS wiki, I found this article:
> http://www.ethernut.de/nutwiki/index.php/Documents/NTN-6_SPI
> Which gives some examples for using the SPI and are very similar to the usage here:
> http://www.ethernut.de/nutwiki/index.php/SPI
> So I tried this:
>
> #define NUMBER_OF_CHANNELS 4
> #define ADC_CONV_PIN 3
> #define ADC_CONV_PORT NUTGPIO_PORTB
>
> NUTSPINODE adc_node = {&spiBus0At91, NULL, 45158500, 0, (NUMBER_OF_CHANNELS*32), 0};
Hello Nikolas,

the initialisation seem fishy. In 2020, is good habit to use modern C
struct initialization like:

NUTSPINODE spi_node = {
    .node_bus  =  &DEF_SPIBUS,
    .node_stat = NULL,
    .node_rate = 1000000,
    .node_mode = SPI_MODE_0,
    .node_bits = 8,
    .node_cs = 0,
    .node_dcb = NULL,
};

.node_bits seems not good in your code. Most SPI IP transfers in units
of 8 bits. But even if the IP can do more, Ethernut device driver must
support it and I am not sure about Atmel. I use Stm32.

Otherwise, I am still missing exact error output from the problem you
had last week. We help you, you help us...

Bye
--
Uwe Bonnes                [hidden email]

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 1623569 ------- Fax. 06151 1623305 ---------
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion
Reply | Threaded
Open this post in threaded view
|

Re: SPI Documentation

Nikolas Becker
Hi Uwe,

First: thanks! I will try that.

Sorry, I didn't know there was something missing from the other issue! I summarize:

- All my mail addresses are not able to receive zip- or exe-files, so none of your compiled qnutconf-version reached me, sadly and I was not able to try it. Is there some kind of webspace to upload it to?

- The version of Thiago gives the same already known issue: the makedefs can not be found:

16:16:04: Creating Makefiles for  in D:/dev/trunk/Ethernut/ethernut_2020_03_30/ethernut50f/nutbld
16:16:04: Creating header files in D:/dev/trunk/Ethernut/ethernut_2020_03_30/ethernut50f/nutbld
16:16:04: ----- Running 'make clean' -----
16:16:05: makefile:38: D:/dev/trunk/Ethernut/ethernut_2020_03_30/nut/Makedefs.: No such file or directory
16:16:05: makefile:51: D:/dev/trunk/Ethernut/ethernut_2020_03_30/nut/Makerules.: No such file or directory
16:16:05: make[1]: *** No rule to make target `D:/dev/trunk/Ethernut/ethernut_2020_03_30/nut/Makerules.'.  Stop.
16:16:05: make: *** [clean] Error 2

- By running nutconfigure from the console, Thiago found that I would build my librarys for the wrong platform (AVR). But since I already chose the platform in nutconfigure with the -m command as arm-gcc, I don't know where I can change any other parameters so the right platform is set?

Best regards,
   Nikolas


-----Urspr√ľngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von [hidden email]
Gesendet: Freitag, 3. April 2020 15:35
An: Ethernut User Chat (English) <[hidden email]>
Betreff: Re: [En-Nut-Discussion] SPI Documentation

Nikolas Becker writes:

> Hi guys,
>
> I'm working now with my ethernut5 and the TCP/IP-functionality is just so nice working out of the box, very happy with it.
>
> Now I need to read data from several ADCs via SPI. And here comes my problem: where can I find some documentation for the SPI device driver?
>
> In the Nut/OS Software manual
> http://www.ethernut.de/pdf/enswm28e.pdf
>  there are some lines regarding SPI on page 45, suggesting the use of NutRegisterSpiDevice(), but not much more.
>
> In the Nut/OS wiki, I found this article:
> http://www.ethernut.de/nutwiki/index.php/Documents/NTN-6_SPI
> Which gives some examples for using the SPI and are very similar to the usage here:
> http://www.ethernut.de/nutwiki/index.php/SPI
> So I tried this:
>
> #define NUMBER_OF_CHANNELS 4
> #define ADC_CONV_PIN 3
> #define ADC_CONV_PORT NUTGPIO_PORTB
>
> NUTSPINODE adc_node = {&spiBus0At91, NULL, 45158500, 0,
> (NUMBER_OF_CHANNELS*32), 0};
Hello Nikolas,

the initialisation seem fishy. In 2020, is good habit to use modern C struct initialization like:

NUTSPINODE spi_node = {
    .node_bus  =  &DEF_SPIBUS,
    .node_stat = NULL,
    .node_rate = 1000000,
    .node_mode = SPI_MODE_0,
    .node_bits = 8,
    .node_cs = 0,
    .node_dcb = NULL,
};

.node_bits seems not good in your code. Most SPI IP transfers in units of 8 bits. But even if the IP can do more, Ethernut device driver must support it and I am not sure about Atmel. I use Stm32.

Otherwise, I am still missing exact error output from the problem you had last week. We help you, you help us...

Bye
--
Uwe Bonnes                [hidden email]

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 1623569 ------- Fax. 06151 1623305 --------- _______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion
Reply | Threaded
Open this post in threaded view
|

Re: SPI Documentation

Uwe Bonnes
Nikolas Becker writes:
> Hi Uwe,
>
> First: thanks! I will try that.
>
> Sorry, I didn't know there was something missing from the other
> issue! I summarize:

Recent nutconfigure does not need  the -m option:
 > nutconfigure -h
nutconfigure: invalid option -- 'h'
Usage: nutconfigure OPTIONS ACTIONS
OPTIONS:
-a<dir>  application directory (Default: <user_dir>/nutapp)
-b<dir>  build directory (Default: <user_dir>/nutbld)
-c<file> configuration file (Required)
-l<dir>  library directory (Default: <user_dir>/nutbld/lib)
-q       quiet (verbose)
-s<dir>  source directory (Default: See below)
-r<file> repository (Default: <src_dir>/conf)
-u<dir>  user directory (Default: See below)
ACTIONS:
create-buildtree
create-apptree
create-usertree
Default for src_dir if not given:
        If configuration file has /nut/conf in path: Use /nut.
        If located elsewhere: Abort.
Default for user_dir if not given:
        If configuration file has /nut/conf in path:
                Use a directory with name of configuration file in /nut/..
        If configuration file is outside nut/conf:
                Use directory where configuration is found.


Compiler is already listed in the conf file:
nut/conf/ethernut50f.conf
ARM_GCC = ""

Bye

--
Uwe Bonnes                [hidden email]

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 1623569 ------- Fax. 06151 1623305 ---------
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion