Forum: Mikrocontroller und Digitale Elektronik SPI_ERROR_TIMEOUT


von DoSch58 (Gast)


Lesenswert?

Hallo zusammen,

ich habe ein Problem bei Konfigurieren eines SPI interfaces. Ich habe 
ein EVK1101 und möchte das SPARE_SPI interface verwenden.
Leider bekomme beim Senden bzw. Empfangen immer ein SPI_ERROR_TIMEOUT 
zurück geliefert. Hab hier im Forum auch den Beispielcode angesehen. 
Aber leider funktioniert es nicht bei mir.

Vielleicht kann mir ja jemand helfen ?


Hier der Code:
1
/*
2
 * Include header files for all drivers that have been imported from
3
 * AVR Software Framework (ASF).
4
 */
5
#include <asf.h>
6
#include "stdio.h"
7
#include "compiler.h"
8
#include "board.h"
9
#include "gpio.h"
10
#include "pm.h"
11
#include "spi.h"
12
13
14
#define CONFIG_SPI_REG          0      //! The SPI channel to set up.
15
#define CONFIG_SPI_MASTER_BAUDRATE    60000    //! Preferred baudrate for the SPI.
16
#define CONFIG_SPI_BITS          8      //! Number of bits in each character (8 to 16).
17
#define CONFIG_SPI_SPCK_DELAY      0      //! Delay before first clock pulse after selecting slave (in PBA clock periods).
18
#define CONFIG_SPI_TRANS_DELAY      0      //! Delay between each transfer/character (in PBA clock periods).
19
#define CONFIG_SPI_STAY_ACT        1      //! Sets this chip to stay active after last transfer to it.
20
#define CONFIG_SPI_SPI_MODE        SPI_MODE_0  //! Which SPI mode to use when transmitting.
21
#define CONFIG_SPI_MODFDIS        0      //! Disables the mode fault detection.
22
                          //! With this bit cleared, the SPI master mode will disable itself if another
23
                          //! master tries to address it.
24
25
static const spi_options_t spi_options = {
26
  .reg = CONFIG_SPI_REG,
27
  .baudrate = CONFIG_SPI_MASTER_BAUDRATE,
28
  .bits = CONFIG_SPI_BITS,
29
  .spck_delay = CONFIG_SPI_SPCK_DELAY,
30
  .trans_delay = CONFIG_SPI_TRANS_DELAY,
31
  .stay_act = CONFIG_SPI_STAY_ACT,
32
  .spi_mode = CONFIG_SPI_SPI_MODE,
33
  .modfdis = CONFIG_SPI_MODFDIS  
34
};
35
36
37
38
39
//#include "own\lcd.h"
40
41
int main (void)
42
{
43
  char line[50];
44
  spi_status_t err;
45
  
46
  sysclk_init();
47
  // Configure Osc0 in crystal mode (i.e. use of an external crystal source, with
48
  // frequency FOSC0) with an appropriate startup time then switch the main clock
49
  // source to Osc0.
50
  pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
51
  
52
  board_init();
53
54
    
55
  static const gpio_map_t SPARE_SPI_GPIO_MAP =
56
    {
57
        {SPARE_SPI_SCK_PIN,          SPARE_SPI_SCK_FUNCTION         },  // SPI Clock.
58
        {SPARE_SPI_MISO_PIN,         SPARE_SPI_MISO_FUNCTION        },  // MISO.
59
        {SPARE_SPI_MOSI_PIN,         SPARE_SPI_MOSI_FUNCTION        },  // MOSI.
60
    {SPARE_SPI_NPCS_PIN,         SPARE_SPI_NPCS_FUNCTION        },  // CS.
61
    };
62
   // Assign I/Os for SPI
63
  gpio_configure_pin(AVR32_TWI_SDA_0_0_PIN, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); // A0 for LCD Display
64
    // Assign I/Os to SPI.
65
    gpio_enable_module(SPARE_SPI_GPIO_MAP,
66
                        sizeof(SPARE_SPI_GPIO_MAP) / sizeof(SPARE_SPI_GPIO_MAP[0]));
67
                
68
  // init spi interface
69
70
  spi_reset(&AVR32_SPI);
71
72
  err = spi_initMaster(&AVR32_SPI, &spi_options);
73
  sprintf(line,"Init Master, Errorcode %i X\n", err);
74
75
  
76
    // set chip register
77
  err = spi_selectChip(&AVR32_SPI,0);
78
  sprintf(line,"Setup Select Chip, Errorcode %i X\n", err);
79
80
  
81
  // set chip register
82
  err = spi_setupChipReg(&AVR32_SPI, &spi_options, FOSC0);
83
  sprintf(line,"Setup ChipRef, Errorcode %i X\n", err);
84
  
85
  // set selection mode 
86
  //err = spi_selectionMode(&AVR32_SPI,0,0,0);
87
  //sprintf(line,"Selection Mode, Errorcode %i X\n", err);
88
  
89
90
  // enable spi interface
91
  spi_enable(&AVR32_SPI);  
92
  
93
  err = spi_is_enabled(&AVR32_SPI);
94
  sprintf(line,"SPI enabled, Errorcode %i X\n", err);
95
  
96
  U16 data;
97
  while (true){
98
    
99
    err = spi_selectChip(&AVR32_SPI, 2);
100
    sprintf(line,"Select Chip, Errorcode %i X\n", err);
101
102
    
103
    err = spi_write(&AVR32_SPI, (unsigned int)'A');
104
    sprintf(line,"SPI write, Errorcode %i X\n", err);
105
106
    err = spi_unselectChip(&AVR32_SPI, 2);
107
    sprintf(line,"Unselect Chip, Errorcode %i X\n", err);
108
109
  }
110
}

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.