Forum: Mikrocontroller und Digitale Elektronik AT32UC3C-EK SPI


von Thomas S. (seitz)


Lesenswert?

Hallo,
meine SPI auf dem AT32UC3C-EK SPI funktioniert nicht. Ich bekomm aber 
keinen clock. was mach ich falsch?
1
#include <asf.h>
2
#define PBC      12000000
3
#define SPI_TMP             (&AVR32_SPI0)
4
#define DummyData 0xFF 
5
 //init spi 0
6
 void init_spi(void){
7
   static const gpio_map_t SPI_GPIO_MAPPING  =
8
  {
9
  {102,0 }, //GPIO102, Function A  // SPI Clock.
10
  {101,0 }, //GPIO101, Function A  // MISO.
11
  {107,0 }, //GPIO107, Function A  // MOSI.
12
  {93,0 }, //GPIO93, Function A  // CS0
13
  };
14
15
  // Assign I/Os to SPI
16
  gpio_enable_module(SPI_GPIO_MAPPING, sizeof(SPI_GPIO_MAPPING) / sizeof(SPI_GPIO_MAPPING[0]));
17
18
  //enable the clock for the spi controller
19
  sysclk_enable_pba_module(SYSCLK_SPI0);
20
21
  //set spi options
22
  spi_options_t spi_options =
23
  {
24
    .baudrate     = 12000000,  // spi baudrate
25
    .bits         = 16,    // number of bits from 8 to 16
26
    .modfdis      = 0,    // disables the mode fault detection
27
    .reg          = 0,    // spi channel
28
    .spck_delay   = 0,    // delay before first clock pulse
29
    .spi_mode     = 1,    // spi mode to use when transmitting
30
    .stay_act     = 0,    // sets this chip to stay active after last transfer
31
    .trans_delay  = 0    // delay between each transfer
32
  };
33
34
  spi_initMaster(SPI_TMP, &spi_options);      // init function
35
  spi_set_master_mode(SPI_TMP);          // set master mode
36
  spi_selectChip(SPI_TMP, 0);              // select a chip
37
  spi_setupChipReg(SPI_TMP, &spi_options, PBC);  // setup chip
38
  spi_enable(SPI_TMP);              // enable spi
39
}
40
41
  
42
43
int main (void){
44
  board_init();
45
  init_spi();
46
47
48
  
49
50
  while (1){
51
    spi_write(SPI_TMP,DummyData); //0xFF tends to be good for dummy data
52
    //spi_read((&AVR32_SPI0),&data_read); //Read data
53
54
  }
55
}

von Ich (Gast)


Lesenswert?

Ich würd zuerst prüfen ob dein Setup generell klappt, z.B. kannst du in 
der main() in einer while(1) Schleife einen Pin toggeln uns siehst du 
das am Oszi? Evtl. klappt schon in board_setup() irgendwas nicht.

Dann würd ich den Return-Wert aller Funktionsaufrufe checken. Meldet 
evtl. einer davon einen Fehler?

von UC3A (Gast)


Lesenswert?

Da fehlt noch nach:
1
spi_initMaster(SPI_TMP, &spi_options);
2
3
// Set selection mode: variable_ps, pcs_decode, delay
4
spi_selectionMode(SPI_TMP, 0, 0, 0);

Wo wird eigentlich Deine System-Clock initialisiert?

Warum versuchst Du nicht erst einmal eines der vielen Beispiele?

von Thomas S. (seitz)


Lesenswert?

Habs zum laufen gebracht. Danke

von Kai S. (hugstuart)


Lesenswert?

Woran lag es denn?

von Thomas S. (seitz)


Lesenswert?

An mehreren Dingen, kann man im nachhinein nicht wirklich sagen

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.