[AVR32] spi_write klappt nur einmal

Gast #1797843
Lesenswert?

Guten Morgen alle zusammen,
ich versuche zur Zeit einen Funk-Chip (RFM12B) über das SPI-Interface 
mit meinem AVR32-Board (EVK1101) zu verbinden.

Ich initialisiere SPI folgendermaßen:
1
static const gpio_map_t SPI_GPIO_MAP =
2
{
3
  {SCK, 0 }, //GPIO15, Function A // SPI Clock.
4
  {MISO, 0 }, //GPIO25, Function A // MISO.
5
  {MOSI, 0 }, //GPIO14, Function A // MOSI.
6
  {NSEL, 0 }, //GPIO16, Function A // CS0
7
};
8

9

10
// SPI options.
11
static const spi_options_t spi_options =
12
{
13
  .reg = 0, //! The SPI channel to set up.
14
  .baudrate = 500000,
15
  .bits = 8, //! Number of bits in each character (8 to 16).
16
  .spck_delay = 0, //! Delay before first clock pulse after selecting slave.
17
  .trans_delay = 4, //! Delay between each transfer/character.
18
  .stay_act = 0, //! Sets this chip to stay active after last transfer to it.
19
  .spi_mode = 1, //! Which SPI mode to use when transmitting.
20
  .modfdis = 0, //! Disables the mode fault detection.
21
}; 
22

23
void init_spi()
24
{
25
 // Assign I/Os to SPI.
26
 if(gpio_enable_module(SPI_GPIO_MAP, sizeof(SPI_GPIO_MAP) / sizeof(SPI_GPIO_MAP[0])) != GPIO_SUCCESS)
27
  show_error();
28

29
 // Initialize as master.
30
 if(spi_initMaster(&AVR32_SPI, &spi_options) != SPI_OK)
31
  show_error();
32

33
 // Set selection mode: variable_ps, pcs_decode, delay.
34
 if(spi_selectionMode(&AVR32_SPI, 0, 0, 0) != SPI_OK)
35
  show_error();
36

37
 if(spi_selectChip(&AVR32_SPI, 0) != SPI_OK)
38
  show_error();
39

40
 if(spi_setupChipReg(&AVR32_SPI, &spi_options, 20000000) != SPI_OK)
41
  show_error();
42

43
 // Enable SPI.
44
 spi_enable(&AVR32_SPI);
45

46
}

Und jetzt würde ich gerne per spi_write() befehle an meinen Chip senden.
Allerdings ist nur das erste Senden erfolgreich, alle anschliessenden 
spi_write() liefern SPI_ERROR_TIMEOUT zurück:
1
while(1)
2
{
3
 spi_status_t status = spi_write(&AVR32_SPI, a);
4
 if(status == SPI_OK)
5
  LED_On(0b00001000);
6
 else if(status == SPI_ERROR_TIMEOUT)
7
  show_error();
8
 else
9
  show_error2();
10
}

Merkwürdigerweise funktioniert es aber wenn ich vor jedem write erneut 
ein init ausführe.
Hat jemand eine Idee was ich falsch mache?

gruß Oliver

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren