EmbDev.net

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


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

Rate this post
0 useful
not useful
Greetings,

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
          spi_initMaster(SPI_EXAMPLE,&my_spi_options);
          //Setup configuration for chip connected to CS1


         spi_setupChipReg(SPI_EXAMPLE,&my_spi_options,sysclk_get_pba_hz());

         //Allow the module to transfer data
          spi_enable(SPI_EXAMPLE);
      }
int status;
int status1;

uint16_t data1;
uint16_t data;

int main(void)
{
 static const gpio_map_t SPI_GPIO_MAP =
  {
    {AVR32_SPI0_SCK_0_0_PIN,AVR32_SPI0_SCK_0_0_FUNCTION},
    {AVR32_SPI0_MOSI_0_0_PIN,AVR32_SPI0_MOSI_0_0_FUNCTION},
    {AVR32_SPI0_MISO_0_0_PIN,AVR32_SPI0_MISO_0_0_FUNCTION},
    {AVR32_SPI0_NPCS_3_0_PIN, //AVR32_SPI0_NPCS_3_0_FUNCTION},
    },
    };

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

  pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);

  sysclk_init();
  sysclk_enable_peripheral_clock(SPI_EXAMPLE);
    spi_init_module();
  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_setupChipReg(SPI_EXAMPLE,&my_spi_options,FOSC0);
  spi_enable(SPI_EXAMPLE);
while(1)
{
  spi_selectChip(SPI_EXAMPLE, SPI_SLAVE); // select the SPI Module
        //Wait for the transmitter to be ready
  while(!spi_is_tx_ready(SPI_EXAMPLE));
        //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
  while(!spi_is_tx_empty(SPI_EXAMPLE));
  //Wait for the transmitter to be ready
  while(!spi_is_tx_ready(SPI_EXAMPLE));
  status1 = spi_write(SPI_EXAMPLE, 0b00010000);
  status1 = spi_write(SPI_EXAMPLE, 0b00000000);
  status1 = spi_read(SPI_EXAMPLE, &data1);
  //Wait for a complete transmission
  while(!spi_is_tx_empty(SPI_EXAMPLE));
  // Deselect the slave
  while(!spi_is_tx_empty(SPI_EXAMPLE));
  spi_unselectChip(SPI_EXAMPLE,SPI_SLAVE);

  }
}

Can someone tell what am i doing wrong?

Regards

Author: marko (Guest)
Posted on:

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

Reply

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.