Forum: Mikrocontroller und Digitale Elektronik SPI geht nicht


von Oli (Gast)


Lesenswert?

Hallo Leute,

ich versuche eine SPI zu testen, aber es klappt nicht. Ich habe den 
PORTD als Master eingestellt und sende 0x55 als test. Den Test PORT isd 
PD7. Am Oxillo wird nichts angezeigt. Kann jemandem dabei mir helfen?

Danke ......Oli


ich benutze Xplain und ATXmega128

hier mein Code:


#define F_CPU 32000000UL
#include <avr/io.h>
#include <stdio.h>
#include <util/delay.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>

#include "avr_compiler.h"
#include "port_driver.h"
#include "pmic_driver.h"
#include "clksys_driver.h"
#include "spi_driver.h"


/  SPI master on PORT D.
SPI_Master_t spiMasterD;

//  Data packet.
SPI_DataPacket_t dataPacket;

//dummy Data for send
char sendData[3]={0x55,0x55,0x55};

/array for received data
char receivedData[3];


void Clk_Init()
{

  CLKSYS_Enable( OSC_RC32MEN_bm );
  CLKSYS_Prescalers_Config( CLK_PSADIV_1_gc, CLK_PSBCDIV_1_1_gc );
  do {} while ( CLKSYS_IsReady( OSC_RC32MRDY_bm ) == 0 );
  CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_RC32M_gc );

}

void SPI_Init(void)

{
  PORTD.DIRSET = PIN4_bm;
  PORTD.PIN4CTRL = PORT_OPC_WIREDANDPULL_gc;
  PORTD.OUTSET = PIN4_bm;

  SPI_MasterInit(&spiMasterD,
                 &SPID,
                 &PORTD,
           false,
                 SPI_MODE_0_gc,
                 SPI_INTLVL_MED_gc,
                 false,
                 SPI_PRESCALER_DIV4_gc);

  PMIC.CTRL |= PMIC_MEDLVLEN_bm;
  sei();

  //Create data packet (SS to slave by PC4)
  SPI_MasterCreateDataPacket(&dataPacket,
                             sendData,
                             receivedData,
                             3,
                             &PORTD,
                             PIN4_bm);



   /* Transmit and receive first data byte. */
  uint8_t status;
  do {
    status = SPI_MasterInterruptTransceivePacket(&spiMasterD, 
&dataPacket);
  } while (status != SPI_OK);

  /* Wait for transmission to complete. */
  while (dataPacket.complete == false) {

  }

}


ISR(SPID_INT_vect)
  {
  SPI_MasterInterruptHandler(&spiMasterD);
  }

int main (void)
{
  Clk_Init();
  SPI_Init();
  sei();
  while(1)
  {
  nop();
  }
}

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.