public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] SPI usage
@ 2007-02-26 14:51 Julien Stéphane
  2007-02-26 14:57 ` Gary Thomas
  0 siblings, 1 reply; 7+ messages in thread
From: Julien Stéphane @ 2007-02-26 14:51 UTC (permalink / raw)
  To: ecos-discuss

[-- Attachment #1: Type: text/plain, Size: 49 bytes --]

sorry, here is my code...
 
Thanks!
Stéphane

[-- Attachment #2: spi1.c --]
[-- Type: text/plain, Size: 5058 bytes --]

#include <stdio.h>
#include <cyg/hal/hal_diag.h>
#include <cyg/io/spi.h>
#include <cyg/io/spi_at91.h>
#include <cyg/io/spi_eb55.h>

#define DEV_NUM 4 //default 0
#define CL_POL 1 //default 1
#define CL_PHA 1 //default 0
#define CL_BRATE 3000000 //default 8192000, 2000000?
#define CS_UP_UDLY 1 //default 1
#define CS_DW_UDLY 1 //default 1
#define TR_BT_UDLY 1 //default 1

static cyg_spi_at91_device_t spi_eb55_device CYG_SPI_DEVICE_ON_BUS(0) = 
{
    .spi_device.spi_bus = &cyg_spi_at91_bus.spi_bus,

    .dev_num     = DEV_NUM,          // Device number
    .cl_pol      = CL_POL,           // Clock polarity (0 or 1)
    .cl_pha      = CL_PHA,           // Clock phase (0 or 1)
    .cl_brate    = CL_BRATE,         // Clock baud rate
    .cs_up_udly  = CS_UP_UDLY,       // Delay in usec between CS up and transfer start
    .cs_dw_udly  = CS_DW_UDLY,       // Delay in usec between transfer end and CS down
    .tr_bt_udly  = TR_BT_UDLY        // Delay in usec between two transfers
};

cyg_spi_device *cyg_spi_eb55_device = &spi_eb55_device.spi_device;

void printAT91_SPI_Configuration(cyg_spi_at91_device_t dev);
void setAT91_SPI_Configuration(cyg_spi_at91_device_t *dev);

void cyg_user_start(void)
{
    cyg_uint8 tx_data0, tx_data1, tx_data2, tx_data3;
    cyg_uint8 rx_data;
    
    printf("Entering application !\n");
    hal_diag_led(0x0);
    
    tx_data0=0x0;
    tx_data1=0x1;
    tx_data2=0x90;
    tx_data3=0x15;
    
    //setAT91_SPI_Configuration(cyg_spi_dataflash_dev0);
    
    cyg_spi_tick(cyg_spi_eb55_device, 0, 10);
    
    printf("Sending data...\n");
    printf("1\n");
    cyg_spi_transaction_begin(cyg_spi_eb55_device);
    printf("2\n");
    cyg_spi_transaction_transfer(cyg_spi_eb55_device, 0, 1, &tx_data0, &rx_data, 0);
    printf("3\n");
    //cyg_spi_transaction_tick(cyg_spi_eb55_device, 0, 1);
    printf("4\n");
    cyg_spi_transaction_end(cyg_spi_eb55_device);
    printf("5\n");
    printf("Datas deceived : %i\n",rx_data);
    
    printf("Sending data...\n");
    printf("1\n");
    cyg_spi_transaction_begin(cyg_spi_eb55_device);
    printf("2\n");
    cyg_spi_transaction_transfer(cyg_spi_eb55_device, 0, 1, &tx_data1, &rx_data, 0);
    printf("3\n");
    //cyg_spi_transaction_tick(cyg_spi_eb55_device, 0, 1);
    printf("4\n");
    cyg_spi_transaction_end(cyg_spi_eb55_device);
    printf("5\n");
    printf("Datas deceived : %i\n",rx_data);
    
    printf("Sending data...\n");
    printf("1\n");
    cyg_spi_transaction_begin(cyg_spi_eb55_device);
    printf("2\n");
    cyg_spi_transaction_transfer(cyg_spi_eb55_device, 0, 1, &tx_data2, &rx_data, 0);
    printf("3\n");
    //cyg_spi_transaction_tick(cyg_spi_eb55_device, 0, 1);
    printf("4\n");
    cyg_spi_transaction_end(cyg_spi_eb55_device);
    printf("5\n");
    printf("Datas deceived : %i\n",rx_data);
    
    printf("Sending data...\n");
    printf("1\n");
    cyg_spi_transaction_begin(cyg_spi_eb55_device);
    printf("2\n");
    cyg_spi_transaction_transfer(cyg_spi_eb55_device, 0, 1, &tx_data3, &rx_data, 0);
    printf("3\n");
    //cyg_spi_transaction_tick(cyg_spi_eb55_device, 0, 1);
    printf("4\n");
    cyg_spi_transaction_end(cyg_spi_eb55_device);
    printf("5\n");
    printf("Datas deceived : %i\n",rx_data);
    
    
    //printAT91_SPI_Configuration(*spi_eb55_device);
    
    /*printf("Sending data...\n");
    cyg_spi_transfer(cyg_spi_eb55_device, 0, 1, &tx_data0, &rx_data);
    cyg_spi_tick(cyg_spi_eb55_device, 0, 1);
    printf("Datas deceived : %i\n",rx_data);
    cyg_spi_transfer(cyg_spi_eb55_device, 0, 1, &tx_data1, &rx_data);
    cyg_spi_tick(cyg_spi_eb55_device, 0, 1);
    printf("Datas deceived : %i\n",rx_data);
    cyg_spi_transfer(cyg_spi_eb55_device, 0, 1, &tx_data2, &rx_data);
    //cyg_spi_tick(cyg_spi_eb55_device, 0, 8);
    printf("Datas deceived : %i\n",rx_data);
    cyg_spi_transfer(cyg_spi_eb55_device, 0, 1, &tx_data3, &rx_data);
    //cyg_spi_tick(cyg_spi_eb55_device, 0, 8);
    printf("Datas deceived : %i\n",rx_data);*/
    
    printf("End of main !\n");
    //cyg_thread_exit();
}

void setAT91_SPI_Configuration(cyg_spi_at91_device_t *dev)
{
    printAT91_SPI_Configuration(*dev);
    
    printf("Setting SPI AT91 devince configuration...\n");
    dev->dev_num = DEV_NUM;
    dev->cl_pol = CL_POL;
    dev->cl_pha = CL_PHA;
    dev->cl_brate = CL_BRATE;
    dev->cs_up_udly = CS_UP_UDLY;
    dev->cs_dw_udly = CS_DW_UDLY;
    dev->tr_bt_udly = TR_BT_UDLY;
    printf("Configuration setted.\n");
    
    printAT91_SPI_Configuration(*dev);
}

void printAT91_SPI_Configuration(cyg_spi_at91_device_t dev)
{
    printf("Printing SPI AT91 device configuration :\n");
    printf("-  -------------\n");
    printf("-  dev_number  = %i\n",dev.dev_num);
    printf("-  cl_polarity = %i\n",dev.cl_pol);
    printf("-  cl_phase    = %i\n",dev.cl_pha);
    printf("-  cl_baudrate = %i\n",dev.cl_brate);
    printf("-  cs_up_udly  = %i\n",dev.cs_up_udly);
    printf("-  cs_dw_udly  = %i\n",dev.cs_dw_udly);
    printf("-  tr_br_udly  = %i\n",dev.tr_bt_udly);
    printf("-  -------------\n");
}

[-- Attachment #3: Type: text/plain, Size: 148 bytes --]

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

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [ECOS] SPI usage
@ 2007-02-26 14:49 Julien Stéphane
  0 siblings, 0 replies; 7+ messages in thread
From: Julien Stéphane @ 2007-02-26 14:49 UTC (permalink / raw)
  To: ecos-discuss; +Cc: Etique Philippe

Hy everybody,
 
I have problems developing an application using SPI on AT91EB55. When I send a tick, then I connot send datas any more because the programm is blocking. If I don't send ticks, it blocks on the next transfer.
 
I have checked the clock phase, clock polarity and chip select. Could it come from an hardware problem or I'm wrong in my code?
 
Thank you very much for your help.... 
Stéphane

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-03-01  6:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-26 14:51 [ECOS] SPI usage Julien Stéphane
2007-02-26 14:57 ` Gary Thomas
2007-02-26 15:01   ` [ECOS] RE : " Julien Stéphane
2007-02-27  4:56   ` [ECOS] Proper Thread Environment (was Re: [ECOS] SPI usage) Chuck McManis
2007-02-27 12:06     ` Gary Thomas
2007-03-01  6:08       ` Chuck McManis
  -- strict thread matches above, loose matches on Subject: below --
2007-02-26 14:49 [ECOS] SPI usage Julien Stéphane

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).