[En-Nut-Discussion] SPI Documentation

Nikolas Becker N.Becker at pemtec.de
Fri Apr 3 14:18:44 CEST 2020


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




More information about the En-Nut-Discussion mailing list