public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: jayant biswas <biswasj@gmail.com>
To: ilijas@siva.com.mk, ecos-discuss@ecos.sourceware.org
Subject: [ECOS] SPI send data
Date: Wed, 01 Jun 2011 09:02:00 -0000	[thread overview]
Message-ID: <BANLkTikmkF7nXX847CWOWGEedk-yrKvQsg@mail.gmail.com> (raw)

Hi Ilija,

Thank you for your response to the previous question, I am using SPI1
and have changed the config accordingly and have noticed with a
voltmeter that the pin PA8 does stay high and goes low when the SPI is
active. I have another question now about sending data. If you take a
look at the timing diagrams on page 10 of the datasheet
(http://www.analog.com/static/imported-files/data_sheets/AD8400_8402_8403.pdf)
for the programmable potentiometer that I am using and then my code
below, could you maybe hint at what I am doing wrong?

Regards,
Jayant

So this code based on the loopback test that comes with the spi package in ecos.

#include <cyg/infra/cyg_type.h>
#include <cyg/infra/testcase.h>         // Test macros
#include <cyg/infra/cyg_ass.h>          // Assertion macros
#include <cyg/infra/diag.h>             // Diagnostic output

#include <cyg/hal/hal_arch.h>           // CYGNUM_HAL_STACK_SIZE_TYPICAL
#include <cyg/kernel/kapi.h>

#include <cyg/io/spi.h>                 // Common SPI API
#include <cyg/io/spi_stm32.h>           // STM32 data structures

#include <string.h>

//---------------------------------------------------------------------------
// Thread data structures.

cyg_uint8 stack [CYGNUM_HAL_STACK_SIZE_TYPICAL];
cyg_thread thread_data;
cyg_handle_t thread_handle;

externC cyg_spi_cortexm_stm32_bus_t cyg_spi_stm32_bus2;

//---------------------------------------------------------------------------
// SPI loopback device driver data structures.

cyg_spi_cortexm_stm32_device_t loopback_device = {
    .spi_device.spi_bus = &cyg_spi_stm32_bus1.spi_bus,
    .dev_num = 0 ,                      // Only 1 device.
    .cl_pol = 1,
    .cl_pha = 1,
    .cl_brate = 8000000,                // Nominal 8Mhz.
    .cs_up_udly = 1,
    .cs_dw_udly = 1,
    .tr_bt_udly = 1,
    .bus_16bit = true, // *** MODIFIED this because my data is 10 bits
};

//---------------------------------------------------------------------------

//const char tx_data[] = {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1}; // To set
maximum resistance at address 00
const char tx_data[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // To set
minimim resistance at address 00
const char tx_data1[] = "Testing extended API...";
const char tx_data2[] = "Testing extended API for a second transaction.";

char rx_data [sizeof(tx_data)];
char rx_data1 [sizeof(tx_data1)];
char rx_data2 [sizeof(tx_data2)];

//---------------------------------------------------------------------------
// Run single loopback transaction using simple transfer API call.

void run_test_1 (cyg_bool polled)
{
    diag_printf ("Test 1 : Simple transfer test (polled = %d).\n",
polled ? 1 : 0);
    cyg_spi_transfer (&loopback_device.spi_device, polled, sizeof (tx_data),
        (const cyg_uint8*) &tx_data[0], (cyg_uint8*) &rx_data[0]);

    diag_printf ("    Tx data : %s\n", tx_data);
    diag_printf ("    Rx data : %s\n", rx_data);
    CYG_ASSERT (memcmp (tx_data, rx_data, sizeof (tx_data)) == 0,
        "Simple transfer loopback failed - mismatched data.\n");
}


//---------------------------------------------------------------------------
// Run all PL022 SPI interface loopback tests.

void run_tests (void)
{
    diag_printf ("Running STM32 SPI driver loopback tests.\n");
    run_test_1 (true);
    CYG_TEST_PASS_FINISH ("Loopback tests ran OK");
}

//---------------------------------------------------------------------------
// User startup - tests are run in their own thread.

void cyg_user_start(void)
{
    CYG_TEST_INIT();
    cyg_thread_create(
        10,                                   // Arbitrary priority
        (cyg_thread_entry_t*) run_tests,      // Thread entry point
        0,                                    //
        "test_thread",                        // Thread name
        &stack[0],                            // Stack
        CYGNUM_HAL_STACK_SIZE_TYPICAL,        // Stack size
        &thread_handle,                       // Thread handle
        &thread_data                          // Thread data structure
    );
    cyg_thread_resume(thread_handle);
    cyg_scheduler_start();
}

//=============================================================================

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

             reply	other threads:[~2011-06-01  9:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-01  9:02 jayant biswas [this message]
2011-06-01 17:19 ` Ilija Stanislevik
2011-06-30 14:20   ` jayant biswas
2011-07-01 16:25     ` Ilija Stanislevik
     [not found]       ` <CAB1rPRM8=a6SRctqUUC_NtPHMcivspb7B2LFWKx+cQ5dvLxAWw@mail.gmail.com>
2011-07-04  9:48         ` jayant biswas
2011-07-04 11:42           ` Manuel Borchers
     [not found]           ` <1309773649.2984.4.camel@netxaccos>
2011-07-04 12:35             ` jayant biswas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BANLkTikmkF7nXX847CWOWGEedk-yrKvQsg@mail.gmail.com \
    --to=biswasj@gmail.com \
    --cc=ecos-discuss@ecos.sourceware.org \
    --cc=ilijas@siva.com.mk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).