[En-Nut-Discussion] SW SPI bus reading data

Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Fri Sep 2 11:38:48 CEST 2016

>>>>> "Aigars" == Aigars  <aigars at egle.cs.rtu.lv> writes:

    Aigars> Hello.  Is there some examples on how to read data from SPI
    Aigars> interface ? For given case I need to read temperature from
    Aigars> MAX6675 thermocouple attached to F port on 2.1B version
    Aigars> board. As I understand there is SW bitbanging possibility in
    Aigars> configuration, but wiki topic on SPI is little to complex for my
    Aigars> level...

All those legacy SPI drivers make things hard to understand. It is also a
pity that the Wiki is offline.  The spibus
driver is the most recent. For spibus do: 

-First, you need to define the pin settings for the bitbang driver. E.g. 
for the nucleo_l476rg board I have:

SBBI0_CS0_PIN   = "4"
SBBI0_CS1_PIN   = "5"
SBBI0_SCK_PIN   = "5"

Either do that in the <board>.conf file or use qnutconf
Device Drivers-> Serial Bit Banged Interface 0

- Now define your device, like

 * \brief First ILI9341 LCD Controller SPI node implementation structure.
NUTSPINODE nodeIli9341_0 = {
    NULL,                       /*!< \brief Pointer to the bus controller driver, node_bus. */
    NULL,                       /*!< \brief Pointer to the bus device driver specific settings, node_stat. */
    ILI9341_0_SPI_RATE,         /*!< \brief Initial clock rate, node_rate. */
    ILI9341_SPI_MODE,           /*!< \brief Initial mode, node_mode. */
    8,                          /*!< \brief Initial data bits, node_bits. */
    FB0_CS_INDEX,               /*!< \brief Chip select, node_cs. */
    &ili9341_0_dcb,             /*!< \brief Pointer to our private device control block, node_dcb. */

Register your device like:
rc = NutRegisterSpiDevice(&DEV_FB, &DEF_SPIBUS, FB0_CS_INDEX);

Now talk to your device lik
    rc = (*bus->bus_alloc) (node, 0);
    data[0] = LS0XX_CMD_CLEAR_ALL;
    data[1] = 0;
    data[2] = 0;
    data[3] = 0;
    if (rc == 0) {
        rc = (*bus->bus_transfer) (node, &data, NULL, 4);
        if (rc == 0) {
            (*bus->bus_wait) (node, NUT_WAIT_INFINITE);
        (*bus->bus_release) (node);
    return rc;

I hope I did not miss anything. Please give feedback on Success/error.

Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 1623569 ------- Fax. 06151 1623305 ---------

More information about the En-Nut-Discussion mailing list