Forum: µC & Digital Electronics ATUC3C-EK problem with SPI CS

Author: marko (Guest)
Posted on:
Attached files:

Rate this post
0 useful
not useful

working with AT32UC3A-Xplained as Master and Accelerometer SCA830-D07 as 
Slave. (one master and one slave)
I have a problem with SPI CS.

On the picture is what i get with my osciloscope( 1. SCK;
                                                  2. MOSI
                                                  3. MISO and
                                                  4. CS).
and on the other 2 pictures is how it should be.

This is my code:

#include <avr32/io.h>
#include "compiler.h"
#include "board.h"
#include "power_clocks_lib.h"
#include "gpio.h"
#include "usart.h"
#include "spi_master.h"
#include "stdio.h"

#  define EXAMPLE_TARGET_PBACLK_FREQ_HZ FOSC0  // PBA clock target 
frequency, in Hz

   // spi otions
    spi_options_t my_spi_options={
      // The SPI channel to set up
      .reg = SPI_SLAVE,
      // Preferred baudrate for the SPI.
      .baudrate = 14400,
      // Number of bits in each character (8 to 16).
      .bits = 8,
      // Delay before first clock pulse after selecting slave (in PBA 
clock periods). (min 5ns für STEVAL-MKI105V1)
      .spck_delay = 0, // ca. 20,0 ns 5
      // Delay between each transfer/character (in PBA clock periods).
      .trans_delay = 0,
      // Sets this chip to stay active after last transfer to it.
      .stay_act = 1,
      // Which SPI mode to use when transmitting.
      .spi_mode = SPI_MODE_1,
      // Disables the mode fault detection.
      // With this bit cleared, the SPI master mode will disable itself 
if another
      // master tries to address it.
      .modfdis = 1

    struct spi_device SPI_DEVICE_EXAMPLE = {
      //! Board specific select id
      .id = SPI_SLAVE };

     void spi_init_module(void)
          //Init SPI module as master
          //Setup configuration for chip connected to CS1


         //Allow the module to transfer data
int status;
int status1;

uint16_t data1;
uint16_t data;

int main(void)
 static const gpio_map_t SPI_GPIO_MAP =
    {AVR32_SPI0_NPCS_3_0_PIN, //AVR32_SPI0_NPCS_3_0_FUNCTION},

  sizeof(SPI_GPIO_MAP) / sizeof(SPI_GPIO_MAP[0]));

  pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);

  spi_master_init(SPI_EXAMPLE); // Initiate the SPI Module 1 as Master
  spi_initMaster(SPI_EXAMPLE, &my_spi_options);
  spi_master_setup_device(SPI_EXAMPLE, &SPI_DEVICE_EXAMPLE, SPI_MODE_0, 
my_spi_options.baudrate, 0); // Parametrization for the SPI Module
  spi_selectChip(SPI_EXAMPLE, SPI_SLAVE); // select the SPI Module
        //Wait for the transmitter to be ready
        //Wait for a complete transmission
  status = spi_write(SPI_EXAMPLE, 0b00010101);
        status = spi_write(SPI_EXAMPLE, 0b00000000); //dummy
  status = spi_read(SPI_EXAMPLE, &data);
  //empty tx
  //Wait for the transmitter to be ready
  status1 = spi_write(SPI_EXAMPLE, 0b00010000);
  status1 = spi_write(SPI_EXAMPLE, 0b00000000);
  status1 = spi_read(SPI_EXAMPLE, &data1);
  //Wait for a complete transmission
  // Deselect the slave


Can someone tell what am i doing wrong?


Author: marko (Guest)
Posted on:

Rate this post
0 useful
not useful
My mistake it is UC3-A3 Xplained board!!!


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.