Ejemplo n.º 1
0
static void spiRecIgnore(size_t len) {
  // clear any data in RX FIFO
  SPI0_MCR = SPI_MCR_MSTR | SPI_MCR_CLR_RXF | SPI_MCR_PCSIS(0x1F);
  // use 16 bit frame to avoid TD delay between frames
  // get one byte if len is odd
  if (len & 1) {
    spiRec();
    len--;
  }
  // initial number of words to push into TX FIFO
  int nf = len/2 < SPI_INITIAL_FIFO_DEPTH ? len/2 : SPI_INITIAL_FIFO_DEPTH;
  for (int i = 0; i < nf; i++) {
    SPI0_PUSHR = SPI_PUSHR_CONT | SPI_PUSHR_CTAS(1) | 0XFFFF;
    len -= 2;
  }
  //uint8_t* limit = buf + len - 2*nf;
  //while (buf < limit) {
  while (len > 0) {
    while (!(SPI0_SR & SPI_SR_RXCTR)) {}
    SPI0_PUSHR = SPI_PUSHR_CONT | SPI_PUSHR_CTAS(1) | 0XFFFF;
    SPI0_POPR;
    len -= 2;
  }
  // limit for rest of RX data
  while (nf > 0) {
    while (!(SPI0_SR & SPI_SR_RXCTR)) {}
    SPI0_POPR;
    nf--;
  }
}
Ejemplo n.º 2
0
        /**
         * Receive multiple bytes from SPI.
         *
         * @param bufr array that stores bytes from SPI.
         * @param n number of bytes to receive.
         */
        void receive(void *bufr, size_t n) {
                int i;
                uint8_t *buf = (uint8_t *)bufr;

                if(n & 1) {
                        *buf++ = receive();
                        n--;
                }

                // clear any data in RX/TX FIFOs, and be certain we are in master mode.
                SPI0_MCR = SPI_MCR_MSTR | SPI_MCR_CLR_RXF | SPI_MCR_CLR_TXF | SPI_MCR_PCSIS(0x1F);
                // initial number of words to push into TX FIFO
                int nf = n / 2 < 3 ? n / 2 : 3;
                for(i = 0; i < nf; i++) {
                        SPI0_PUSHR = SPI_PUSHR_CONT | SPI_PUSHR_CTAS(1) | 0XFFFF;
                }
                uint8_t* limit = buf + n - 2 * nf;
                while(buf < limit) {
                        while(!(SPI0_SR & SPI_SR_RXCTR));
                        SPI0_PUSHR = SPI_PUSHR_CONT | SPI_PUSHR_CTAS(1) | 0XFFFF;
                        uint16_t w = SPI0_POPR;
                        *buf++ = w >> 8;
                        *buf++ = w & 0XFF;
                }
                // limit for rest of RX data
                limit += 2 * nf;
                while(buf < limit) {
                        while(!(SPI0_SR & SPI_SR_RXCTR));
                        uint16_t w = SPI0_POPR;
                        *buf++ = w >> 8;
                        *buf++ = w & 0XFF;
                }

        }
Ejemplo n.º 3
0
/** SPI receive multiple bytes */
static uint8_t spiRec(uint8_t* buf, size_t len) {
  // clear any data in RX FIFO
  SPI0_MCR = SPI_MCR_MSTR | SPI_MCR_CLR_RXF | SPI_MCR_PCSIS(0x1F);
  // use 16 bit frame to avoid TD delay between frames
  // get one byte if len is odd
  if (len & 1) {
    *buf++ = spiRec();
    len--;
  }
  // initial number of words to push into TX FIFO
  int nf = len/2 < SPI_INITIAL_FIFO_DEPTH ? len/2 : SPI_INITIAL_FIFO_DEPTH;
  for (int i = 0; i < nf; i++) {
    SPI0_PUSHR = SPI_PUSHR_CONT | SPI_PUSHR_CTAS(1) | 0XFFFF;
  }
  uint8_t* limit = buf + len - 2*nf;
  while (buf < limit) {
    while (!(SPI0_SR & SPI_SR_RXCTR)) {}
    SPI0_PUSHR = SPI_PUSHR_CONT | SPI_PUSHR_CTAS(1) | 0XFFFF;
    uint16_t w = SPI0_POPR;
    *buf++ = w >> 8;
    *buf++ = w & 0XFF;
  }
  // limit for rest of RX data
  limit += 2*nf;
  while (buf < limit) {
    while (!(SPI0_SR & SPI_SR_RXCTR)) {}
    uint16_t w = SPI0_POPR;
    *buf++ = w >> 8;
    *buf++ = w & 0XFF;
  }
  return 0;
}
Ejemplo n.º 4
0
/** SPI send multiple bytes */
static void spiSend(const uint8_t* output, size_t len) {
  // clear any data in RX FIFO
  SPI0_MCR = SPI_MCR_MSTR | SPI_MCR_CLR_RXF | SPI_MCR_PCSIS(0x1F);
  // use 16 bit frame to avoid TD delay between frames
  // send one byte if len is odd
  if (len & 1) {
    spiSend(*output++);
    len--;
  }
  // initial number of words to push into TX FIFO
  int nf = len/2 < SPI_INITIAL_FIFO_DEPTH ? len/2 : SPI_INITIAL_FIFO_DEPTH;
  // limit for pushing data into TX fifo
  const uint8_t* limit = output + len;
  for (int i = 0; i < nf; i++) {
    uint16_t w = (*output++) << 8;
    w |= *output++;
    SPI0_PUSHR = SPI_PUSHR_CONT | SPI_PUSHR_CTAS(1) | w;
  }
  // write data to TX FIFO
  while (output < limit) {
    uint16_t w = *output++ << 8;
    w |= *output++;
    while (!(SPI0_SR & SPI_SR_RXCTR)) {}
    SPI0_PUSHR = SPI_PUSHR_CONT | SPI_PUSHR_CTAS(1) | w;
    SPI0_POPR;
  }
  // wait for data to be sent
  while (nf) {
    while (!(SPI0_SR & SPI_SR_RXCTR)) {}
    SPI0_POPR;
    nf--;
  }
}
Ejemplo n.º 5
0
        /**
         * Send an array of bytes.
         *
         * @param bufr array of bytes to send
         * @param n number of bytes to send
         */
        void send(void *bufr, size_t n) {
                int i;
                int nf;
                uint8_t *buf = (uint8_t *)bufr;

                if(n & 1) {
                        send(*buf++);
                        n--;
                }
                // clear any data in RX/TX FIFOs, and be certain we are in master mode.
                SPI0_MCR = SPI_MCR_MSTR | SPI_MCR_CLR_RXF | SPI_MCR_CLR_TXF | SPI_MCR_PCSIS(0x1F);
                // initial number of words to push into TX FIFO
                nf = n / 2 < 3 ? n / 2 : 3;
                // limit for pushing data into TX fifo
                uint8_t* limit = buf + n;
                for(i = 0; i < nf; i++) {
                        uint16_t w = (*buf++) << 8;
                        w |= *buf++;
                        SPI0_PUSHR = SPI_PUSHR_CONT | SPI_PUSHR_CTAS(1) | w;
                }
                // write data to TX FIFO
                while(buf < limit) {
                        uint16_t w = *buf++ << 8;
                        w |= *buf++;
                        while(!(SPI0_SR & SPI_SR_RXCTR));
                        SPI0_PUSHR = SPI_PUSHR_CONT | SPI_PUSHR_CTAS(1) | w;
                        SPI0_POPR;
                }
                // wait for data to be sent
                while(nf) {
                        while(!(SPI0_SR & SPI_SR_RXCTR));
                        SPI0_POPR;
                        nf--;
                }
        }
Ejemplo n.º 6
0
//! Transmit a 32-bit word with the target 
//!
//! @param send    - data to send
//!
//! @return BDM_RC_OK => success
//!
uint8_t spi_tx32(const uint8_t *data) {
   SPI0_PUSHR = SPI_PUSHR_CTAS(ctas_8bit)|SPI_PUSHR_PCS(0x1)|SPI_PUSHR_CONT_MASK|SPI_PUSHR_TXDATA(*data++);
   SPI0_PUSHR = SPI_PUSHR_CTAS(ctas_8bit)|SPI_PUSHR_PCS(0x1)|SPI_PUSHR_CONT_MASK|SPI_PUSHR_TXDATA(*data++);
   SPI0_PUSHR = SPI_PUSHR_CTAS(ctas_8bit)|SPI_PUSHR_PCS(0x1)|SPI_PUSHR_CONT_MASK|SPI_PUSHR_TXDATA(*data++);
   SPI0_PUSHR = SPI_PUSHR_CTAS(ctas_8bit)|SPI_PUSHR_PCS(0x1)|SPI_PUSHR_CONT_MASK|SPI_PUSHR_TXDATA(*data++)|SPI_PUSHR_EOQ_MASK; 
   while ((SPI0_SR & SPI_SR_EOQF_MASK) == 0) {
   }
   SPI0_SR = SPI_SR_EOQF_MASK;
   return BDM_RC_OK;
}
Ejemplo n.º 7
0
/** SPI send multiple bytes */
void SdSpi::send(const uint8_t* buf , size_t n) {
  // clear any data in RX FIFO
  SPI0_MCR = SPI_MCR_MSTR | SPI_MCR_CLR_RXF | SPI_MCR_PCSIS(0x1F);
#if SPI_USE_8BIT_FRAME
  // initial number of bytes to push into TX FIFO
  int nf = n < SPI_INITIAL_FIFO_DEPTH ? n : SPI_INITIAL_FIFO_DEPTH;
  // limit for pushing data into TX fifo
  const uint8_t* limit = buf + n;
  for (int i = 0; i < nf; i++) {
    SPI0_PUSHR = *buf++;
  }
  // write data to TX FIFO
  while (buf < limit) {
    while (!(SPI0_SR & SPI_SR_RXCTR)) {}
    SPI0_PUSHR = *buf++;
    SPI0_POPR;
  }
  // wait for data to be sent
  while (nf) {
    while (!(SPI0_SR & SPI_SR_RXCTR)) {}
    SPI0_POPR;
    nf--;
  }
#else  // SPI_USE_8BIT_FRAME
  // use 16 bit frame to avoid TD delay between frames
  // send one byte if n is odd
  if (n & 1) {
    send(*buf++);
    n--;
  }
  // initial number of words to push into TX FIFO
  int nf = n/2 < SPI_INITIAL_FIFO_DEPTH ? n/2 : SPI_INITIAL_FIFO_DEPTH;
  // limit for pushing data into TX fifo
  const uint8_t* limit = buf + n;
  for (int i = 0; i < nf; i++) {
    uint16_t w = (*buf++) << 8;
    w |= *buf++;
    SPI0_PUSHR = SPI_PUSHR_CONT | SPI_PUSHR_CTAS(1) | w;
  }
  // write data to TX FIFO
  while (buf < limit) {
    uint16_t w = *buf++ << 8;
    w |= *buf++;
    while (!(SPI0_SR & SPI_SR_RXCTR)) {}
    SPI0_PUSHR = SPI_PUSHR_CONT | SPI_PUSHR_CTAS(1) | w;
    SPI0_POPR;
  }
  // wait for data to be sent
  while (nf) {
    while (!(SPI0_SR & SPI_SR_RXCTR)) {}
    SPI0_POPR;
    nf--;
  }
#endif  // SPI_USE_8BIT_FRAME
}
Ejemplo n.º 8
0
/** SPI receive multiple bytes */
uint8_t SdSpi::receive(uint8_t* buf, size_t n) {
  // clear any data in RX FIFO
  SPI0_MCR = SPI_MCR_MSTR | SPI_MCR_CLR_RXF | SPI_MCR_PCSIS(0x1F);
#if SPI_USE_8BIT_FRAME
  // initial number of bytes to push into TX FIFO
  int nf = n < SPI_INITIAL_FIFO_DEPTH ? n : SPI_INITIAL_FIFO_DEPTH;
  for (int i = 0; i < nf; i++) {
    SPI0_PUSHR = 0XFF;
  }
  // limit for pushing dummy data into TX FIFO
  uint8_t* limit = buf + n - nf;
  while (buf < limit) {
    while (!(SPI0_SR & SPI_SR_RXCTR)) {}
    SPI0_PUSHR = 0XFF;
    *buf++ = SPI0_POPR;
  }
  // limit for rest of RX data
  limit += nf;
  while (buf < limit) {
    while (!(SPI0_SR & SPI_SR_RXCTR)) {}
    *buf++ = SPI0_POPR;
  }
#else  // SPI_USE_8BIT_FRAME
  // use 16 bit frame to avoid TD delay between frames
  // get one byte if n is odd
  if (n & 1) {
    *buf++ = receive();
    n--;
  }
  // initial number of words to push into TX FIFO
  int nf = n/2 < SPI_INITIAL_FIFO_DEPTH ? n/2 : SPI_INITIAL_FIFO_DEPTH;
  for (int i = 0; i < nf; i++) {
    SPI0_PUSHR = SPI_PUSHR_CONT | SPI_PUSHR_CTAS(1) | 0XFFFF;
  }
  uint8_t* limit = buf + n - 2*nf;
  while (buf < limit) {
    while (!(SPI0_SR & SPI_SR_RXCTR)) {}
    SPI0_PUSHR = SPI_PUSHR_CONT | SPI_PUSHR_CTAS(1) | 0XFFFF;
    uint16_t w = SPI0_POPR;
    *buf++ = w >> 8;
    *buf++ = w & 0XFF;
  }
  // limit for rest of RX data
  limit += 2*nf;
  while (buf < limit) {
    while (!(SPI0_SR & SPI_SR_RXCTR)) {}
    uint16_t w = SPI0_POPR;
    *buf++ = w >> 8;
    *buf++ = w & 0XFF;
  }
#endif  // SPI_USE_8BIT_FRAME
  return 0;
}
Ejemplo n.º 9
0
//=========================================================================
//函数名称:spi_send
//函数参数:spin:SPI通道号。
//          data[]:需要发送的数据。
//          len:数据长度。
//函数返回:无
//功能概要:SPI发送数据。
//=========================================================================
void spi_send(SPIn spin,u8 data[],u32 len)
{
    u32 i = 0;
    u8 temp;
    SPI_TX_WAIT(spin);

    do
    {
        /*************  清标志位  ***************/
        SPI_SR_REG(SPIN[spin]) = (SPI_SR_EOQF_MASK
                                | SPI_SR_TFUF_MASK
                                | SPI_SR_TFFF_MASK
                                | SPI_SR_RFOF_MASK
                                | SPI_SR_RFDF_MASK
                                );
    
        /************** 清FIFO计数器 **************/
        SPI_MCR_REG(SPIN[spin])    |=  (SPI_MCR_CLR_TXF_MASK     //Clear TX FIFO.写1清 Tx FIFO counter
                                   |SPI_MCR_CLR_RXF_MASK     //Clear RX FIFO. 写1清 the Rx FIFO counter.
                                   );
        //SPI_SR_REG(SPIN[spin]) |= SPI_SR_RFDF_MASK;
    }while( (SPI_SR_REG(SPIN[spin]) & SPI_SR_RFDF_MASK));   //如果 Rx FIFO 非空,则清FIFO.

    /***************** 发送len-1个数据 *******************/                                                ;
    for(i = 0;i < (len-1);i++)
    {
        //DELAY_MS(1); 
        SPI_PUSHR_REG(SPIN[spin]) = 0 
                                | SPI_PUSHR_CONT_MASK   //Continuous Peripheral Chip Select Enable,1为 传输期间保持PCSn信号 ,即继续传输数据
                                | SPI_PUSHR_CTAS(0)
                                | SPI_PUSHR_TXDATA(data[i]);    //要传输的数据
        
        while( !(SPI_SR_REG(SPIN[spin]) & SPI_SR_RFDF_MASK));    //RFDF为1,Rx FIFO is not empty.
        temp = (u8)SPI_POPR_REG(SPIN[spin]);    //读取一次接收的数据    
        SPI_SR_REG(SPIN[spin]) |= SPI_SR_RFDF_MASK;
    }

    /***************** 发送最后一个数据 *******************/    
    SPI_PUSHR_REG(SPIN[spin]) = 0 
                   | SPI_PUSHR_CTAS(0)
                   | SPI_PUSHR_EOQ_MASK         //End Of Queue,1为 传输SPI最后的数据
                   | SPI_PUSHR_TXDATA(data[i]); 
    
    SPI_EOQF_WAIT(spin);    //要及时把RX FIFO的东西清掉,不然这里就无限等待
    
    while( !(SPI_SR_REG(SPIN[spin]) & SPI_SR_RFDF_MASK));    //RFDF为1,Rx FIFO is not empty.
    temp = (u8)SPI_POPR_REG(SPIN[spin]);    //读取一次接收的数据          
    //SPI_SR_REG(SPIN[spin]) |= SPI_SR_RFDF_MASK;
    

}
Ejemplo n.º 10
0
//! Receive a 32-bit word from the target 
//!
//! @param receive - data received
//!
//! @return BDM_RC_OK => success
//!
uint8_t spi_rx32(uint8_t *receive) {
   SPI0_PUSHR = SPI_PUSHR_CTAS(ctas_8bit)|SPI_PUSHR_PCS(0x1)|SPI_PUSHR_CONT_MASK|SPI_PUSHR_TXDATA(0);
   SPI0_PUSHR = SPI_PUSHR_CTAS(ctas_8bit)|SPI_PUSHR_PCS(0x1)|SPI_PUSHR_CONT_MASK|SPI_PUSHR_TXDATA(0);
   SPI0_PUSHR = SPI_PUSHR_CTAS(ctas_8bit)|SPI_PUSHR_PCS(0x1)|SPI_PUSHR_CONT_MASK|SPI_PUSHR_TXDATA(0);
   SPI0_PUSHR = SPI_PUSHR_CTAS(ctas_8bit)|SPI_PUSHR_PCS(0x1)|SPI_PUSHR_CONT_MASK|SPI_PUSHR_TXDATA(0)|SPI_PUSHR_EOQ_MASK; 
   while ((SPI0_SR & SPI_SR_EOQF_MASK) == 0) {
   }
   SPI0_SR = SPI_SR_EOQF_MASK;
   *receive++  = SPI0_POPR;
   *receive++  = SPI0_POPR;
   *receive++  = SPI0_POPR;
   *receive++  = SPI0_POPR;
   return BDM_RC_OK;
}
Ejemplo n.º 11
0
/*
 * To read data from a LCD register, this function sets the register index,
 * and then sends out 0x73 and wait for reply
 */
static unsigned short SpiReadDataWord(unsigned char reg)
{
  unsigned short value, data;
  unsigned short data2;

  //Set register pointer
  data=0x7000 | reg;

  // wait write buffer not full flag
  while (!(SPI2_SR & SPI_SR_TFFF_MASK)){};

  // Assert CS0, Use config 0
  SPI2_PUSHR = SPI_PUSHR_PCS(1 << (0)) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_TXDATA((unsigned short)data);

  while (!(SPI2_SR & SPI_SR_TCF_MASK)){};// while shift-out complete
  SPI2_SR = SPI_SR_TCF_MASK;           // clear flag


  //Tell it to do a read by sending out 0x73
  data=0x7300;
  data2=0x0000;

  //Halt SPI from sending out anything
  SPI2_MCR  |= SPI_MCR_HALT_MASK;

  // wait write buffer not full flag
  while (!(SPI2_SR & SPI_SR_TFFF_MASK)){};

  // Assert CS0, Use config 0, write two words at once to have CW low long enough
  //  to let data be recieved.
  SPI2_PUSHR = SPI_PUSHR_CONT_MASK | SPI_PUSHR_PCS(1 << (0)) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_TXDATA((unsigned short)data);
  SPI2_PUSHR = SPI_PUSHR_PCS(1 << (0)) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_TXDATA((unsigned short)data2);


  //Send out both data words back to back using the FIFO
  SPI2_MCR &= (~ SPI_MCR_HALT_MASK);

  while (!(SPI2_SR & SPI_SR_TCF_MASK)){};// while shift-out complete
  //while (!(SPI2_SR & SPI_SR_RCF_MASK)){};// while shift-out complete
  SPI2_SR = SPI_SR_TCF_MASK;           // clear flag

  time_delay_ms(5);

  //Data returned from LCD should be in POPR now
  value = SPI2_POPR ;  //garbage
  value = SPI2_POPR ;  //good data

  return value;
}
Ejemplo n.º 12
0
/*
 * LPLD_SPI_Master_WriteRead
 * K60主机SPI向从机写数据,并读取从机数据
 * 
 * 参数:
 *    spix--SPI选择
 *      |__SPI0 -选择SPI0模块
 *      |__SPI1 -选择SPI1模块
 *      |__SPI2 -选择SPI2模块
 *    data--要发送数据
 *      |__单位为一个字节,8位
 *    pcsx--CS片选端口号
 *      |__SPI_PCS0 -0号片选(SPI0、SPI1、SPI2含有)
 *      |__SPI_PCS1 -1号片选(SPI0、SPI1、SPI2含有)
 *      |__SPI_PCS2 -2号片选(SPI0、SPI1含有)
 *      |__SPI_PCS3 -3号片选(SPI0、SPI1含有)
 *      |__SPI_PCS4 -4号片选(SPI0含有)
 *      |__SPI_PCS5 -5号片选(SPI0含有)
 *    pcs_state--一帧数据传输完成后CS的状态
 *      |__SPI_PCS_ASSERTED -保持片选有效,PCS信号保持为低电平
 *      |__SPI_PCS_INACTIVE -片选无效,PCS信号变为高电平
 * 输出:
 *    读取从机8位的数据
 */
uint8 LPLD_SPI_Master_WriteRead(SPI_MemMapPtr spix,uint8 data,uint8 pcsx,uint8 pcs_state)
{
  uint8 temp = 0;
  
  //PUSHR - DSPI PUSH Tx FIFO register In Master mode
  //CONT continuos peripheral chip select enable 
  //CONT = 1 return inactive
  //CONT = 0 kepp ASSERT
     spix->PUSHR  = (((uint32_t)(((uint32_t)(pcs_state))<<SPI_PUSHR_CONT_SHIFT))&SPI_PUSHR_CONT_MASK)
               |SPI_PUSHR_CTAS(0)
               |SPI_PUSHR_PCS(pcsx)
               |data;                 
  if (!pcs_state)
      spix->PUSHR |= SPI_PUSHR_EOQ_MASK;
 
    //直到传输完成
  while(!(spix->SR & SPI_SR_TCF_MASK));
  spix->SR |= SPI_SR_TCF_MASK ;               
  
  while(!(spix->SR & SPI_SR_RFDF_MASK));
     //read date
  temp = (uint8)(spix->POPR & 0xff);           
  spix->SR |= SPI_SR_RFDF_MASK;                
  return temp;
  
}
Ejemplo n.º 13
0
/***********************************************************************************************
 功能:SPI 读写一次数据
 形参:SPICSMap SPI 片选通道定义
       @arg SPI0_PCS0_PA14: SPI0通道 PCS0 PA14引脚
			 @arg ...
			 Data: 需要发送的数据
			 PCS_State: 片选信号状态
			 @arg SPI_PCS_Asserted: 发送完数据后 片选信号拉高
			 @arg SPI_PCS_Inactive: 发送完数据后 片选信号保持低电平
 返回:接收到的数据
 详解:0
************************************************************************************************/
uint16_t SPI_ReadWriteByte(uint32_t SPICSMap,uint16_t Data,uint16_t PCS_State)
{
	uint32_t temp = 0;
	SPI_Type *SPIx = NULL;
	SPI_CSMapTypeDef *pSPI_CSMap = (SPI_CSMapTypeDef*)&(SPICSMap);
	//参数检查
	assert_param(IS_SPI_PCS_STATE(PCS_State));
	assert_param(IS_SPI_PCS_CHL(SPICSMap));
	//找出SPI端口
	switch(pSPI_CSMap->SPI_Index)
	{
		case 0:
			SPIx = SPI0;
			break;
		case 1:
			SPIx = SPI1;
			break;
		case 2:
			SPIx = SPI2;
			break;
		default:break;
	}
	while((SPIx->SR & SPI_SR_TFFF_MASK) == 0){};  //等待发送缓冲区有空位
	SPIx->PUSHR = (((uint32_t)(((uint32_t)(PCS_State))<<SPI_PUSHR_CONT_SHIFT))&SPI_PUSHR_CONT_MASK) //是否拉起CS
							 | SPI_PUSHR_CTAS(1)
						   | SPI_PUSHR_PCS(1<<(pSPI_CSMap->SPI_PCS_CH_Index))//使能信号
						 	 | SPI_PUSHR_TXDATA(Data); //写数据
	while(!(SPIx->SR & SPI_SR_TCF_MASK)){};     //等待发送完成
  SPIx->SR |= SPI_SR_TCF_MASK ;               //清除发送缓冲标志位
  //使接收缓冲器为空
  while((SPIx->SR & SPI_SR_RFDF_MASK) == 0){};   //RX FIFO 未接收到数据则一直等待
  temp = SPIx->POPR;           //数据以32位形式存在POPR中,转化格式 
  while((SPIx->SR & SPI_SR_RFDF_MASK) == 0){};   //RX FIFO 未接收到数据则一直等待
  return temp;
}
Ejemplo n.º 14
0
/*********************************************************
* Name: SPI_Send_byte
* Desc: Send one byte 
* Parameter: The byte to be sent
* Return: None
**********************************************************/
void SPI_Send_byte(uint_8 u8Data)
{
    /*Body*/
    /* Check the status flag */
    if(SPI1_SR & SPI_SR_EOQF_MASK)
    {
        /* Clear the EOQF by writting a 1 to it */
        SPI1_SR |= SPI_SR_EOQF_MASK;
    }/*Endif*/

    /* Write the DSPI_PUSHR register */
    SPI1_PUSHR = (  SPI_PUSHR_CTAS(0)        | 
                    SPI_PUSHR_EOQ_MASK       |
                    SPI_PUSHR_CTCNT_MASK     |
                    SPI_PUSHR_PCS(1)         |
                    SPI_PUSHR_TXDATA(u8Data)); 
    /* Write the clock and transfer attributes: master clock and frame size (8 bits) */
    SPI1_CTAR0 = (  SPI_CTAR_SLAVE_FMSZ(7)      | 
                    gSPI_BeforeTransfDelay      |
                    gSPI_AfterTransfDelay       |
                    gSPI_InterTransfDelay       |
                    gSPI_BaudRate);

    /* Start the transfer */
    SPI1_MCR &= ~SPI_MCR_HALT_MASK;
    
    /* Wait until the transfer has been finished */
    while(!(SPI1_SR & SPI_SR_EOQF_MASK))
    {
        Watchdog_Reset();
    }/*EndWhile*/
    /* Clear the EOQF by writting a 1 to it */
    SPI1_SR |= SPI_SR_EOQF_MASK;
}/*EndBody*/
Ejemplo n.º 15
0
//! Transmit a 8-bit word with the target 
//!
//! @param send    - data to send
//!
//! @return BDM_RC_OK => success
//!
uint8_t spi_tx8(uint8_t data) {
   SPI0_PUSHR = SPI_PUSHR_CTAS(ctas_8bit)|SPI_PUSHR_EOQ_MASK|SPI_PUSHR_PCS(0x1)|SPI_PUSHR_TXDATA(data); 
   while ((SPI0_SR & SPI_SR_EOQF_MASK) == 0) {
   }
   SPI0_SR = SPI_SR_EOQF_MASK;
   return BDM_RC_OK;
}
Ejemplo n.º 16
0
/*
 * LPLD_SPI_Master_Write
 * K60主机SPI向从机写数据
 * 
 * 参数:
 *    spix--SPI选择
 *      |__SPI0 -选择SPI0模块
 *      |__SPI1 -选择SPI1模块
 *      |__SPI2 -选择SPI2模块
 *    data--要发送数据
 *      |__单位为一个字节,8位
 *    pcsx--CS片选端口号
 *      |__SPI_PCS0  -0号片选(SPI0、SPI1、SPI2含有)
 *      |__SPI_PCS1  -1号片选(SPI0、SPI1、SPI2含有)
 *      |__SPI_PCS2  -2号片选(SPI0、SPI1含有)
 *      |__SPI_PCS3  -3号片选(SPI0、SPI1含有)
 *      |__SPI_PCS4  -4号片选(SPI0含有)
 *      |__SPI_PCS5  -5号片选(SPI0含有)
 *    pcs_state--一帧数据传输完成后CS的状态
 *      |__SPI_PCS_ASSERTED -保持片选有效,PCS信号保持为低电平
 *      |__SPI_PCS_INACTIVE -片选无效,PCS信号变为高电平
 */
void LPLD_SPI_Master_Write(SPI_MemMapPtr spix,uint8 data,uint8 pcsx,uint8 pcs_state)
{  
  spix->PUSHR = (((uint32_t)(((uint32_t)(pcs_state))<<SPI_PUSHR_CONT_SHIFT)) & SPI_PUSHR_CONT_MASK)
               |SPI_PUSHR_CTAS(0)
               |SPI_PUSHR_PCS(pcsx)
               |data; 
  if (!pcs_state)
      spix->PUSHR |= SPI_PUSHR_EOQ_MASK;
  while(!(spix->SR & SPI_SR_TCF_MASK));
  spix->SR |= SPI_SR_TCF_MASK ;            
}
Ejemplo n.º 17
0
/**
  * @brief  .
  * @param  None
  * @retval None
  */
void _ILI_SendDummyData (void)
{
	uint16_t receive;
	while (ILI_SPI->SR & SPI_SR_TFFF_MASK == 0);
	ILI_SPI->PUSHR = (SPI_PUSHR_CTAS(0)
			|SPI_PUSHR_TXDATA(0x1ff));
	while (!(ILI_SPI->SR&SPI_SR_TCF_MASK));
	ILI_SPI->SR |= SPI_SR_TCF_MASK;
	while ((ILI_SPI->SR & SPI_SR_RFDF_MASK)==0);
	receive = ILI_SPI->POPR;
	while ((ILI_SPI->SR & SPI_SR_RFDF_MASK) == 0);
}
Ejemplo n.º 18
0
/**
  * @brief  get two ad7687 conver data,
  * @param  None
  * @retval None
  */
void AD7687_GetConverData (uint16_t *ad)
{
	_AD7687_Send_aclock ();	
	while((AD7687_SPI->SR & SPI_SR_TFFF_MASK) == 0){};		
	AD7687_SPI->PUSHR = SPI_PUSHR_CTAS(1)
						| SPI_PUSHR_TXDATA(0);		
	while(!(AD7687_SPI->SR & SPI_SR_TCF_MASK)){};		
	AD7687_SPI->SR |= SPI_SR_TCF_MASK;		
	while((AD7687_SPI->SR & SPI_SR_RFDF_MASK) == 0);   //RX FIFO 未接收到数据则一直等待
	ad[0] = AD7687_SPI->POPR;							//B通道 交流电流 正极电压
	while((AD7687_SPI->SR & SPI_SR_RFDF_MASK) == 0){};   //RX FIFO 未接收到数据则一直等待

	while((AD7687_SPI->SR & SPI_SR_TFFF_MASK) == 0){};
	AD7687_SPI->PUSHR = SPI_PUSHR_CTAS(1)
						| SPI_PUSHR_TXDATA(0);
	while(!(AD7687_SPI->SR & SPI_SR_TCF_MASK)){};
	AD7687_SPI->SR |= SPI_SR_TCF_MASK;
	while((AD7687_SPI->SR & SPI_SR_RFDF_MASK) == 0){};
	ad[1] = AD7687_SPI->POPR;							////A通道 交流电压 负极电压
	while((AD7687_SPI->SR & SPI_SR_RFDF_MASK) == 0){};   //RX FIFO 未接收到数据则一直等待
}
Ejemplo n.º 19
0
  //-----------------------------------------------------------------------------
  // FUNCTION:    D4DLCDHW_SendDataWord_Kinetis_Spi
  // SCOPE:       Low Level Driver API function
  // DESCRIPTION: The function send the one 16 bit variable into LCD
  //
  // PARAMETERS:  unsigned short value    variable to send
  //
  // RETURNS:     none
  //-----------------------------------------------------------------------------
  static void D4DLCDHW_SendDataWord_Kinetis_Spi(unsigned short value)
  {

    // wait write buffer not full flag
    while (!(D4DLCD_SPI_SR & SPI_SR_TFFF_MASK)){};

    // Assert CS0, Use config 0
    D4DLCD_SPI_PUSHR = SPI_PUSHR_PCS(1 << (D4DLCD_SPI_PCS_ID)) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_TXDATA((unsigned short)value);

    while (!(D4DLCD_SPI_SR & SPI_SR_TCF_MASK)){};// while shift-out complete
    D4DLCD_SPI_SR = SPI_SR_TCF_MASK;           // clear flag
  }
Ejemplo n.º 20
0
/**
  * @brief  .
  * @param  None
  * @retval None
  */
uint16_t ILI_SendReceiveNcont (uint16_t data)
{
	uint16_t receive;
	while (ILI_SPI->SR & SPI_SR_TFFF_MASK == 0);
	ILI_SPI->PUSHR = (SPI_PUSHR_CTAS(0)
			|SPI_PUSHR_PCS(1<<1)
			|SPI_PUSHR_TXDATA(data));
	while (!(ILI_SPI->SR&SPI_SR_TCF_MASK));
	ILI_SPI->SR |= SPI_SR_TCF_MASK;
	while ((ILI_SPI->SR & SPI_SR_RFDF_MASK)==0);
	receive = ILI_SPI->POPR;
	while ((ILI_SPI->SR & SPI_SR_RFDF_MASK) == 0);
	return receive;
}
Ejemplo n.º 21
0
Archivo: spi.c Proyecto: aarzho/k60
/**
 *    @brief  SPI发送数据
 * 
 *    @param   spino   SPI通道号
 *    @param   data[]  需要发送的数据  
 *    @param   len     需要发送的数据 
 */
void spi_snd(uint8_t spino, uint8_t data[], uint32_t len)
{
    uint32_t i = 0;
    SPI_MemMapPtr base_addr = spi_get_base_address(spino);
        
    SPI_SR_REG(base_addr) = (SPI_SR_EOQF_MASK
         | SPI_SR_TFUF_MASK
         | SPI_SR_TFFF_MASK
         | SPI_SR_RFOF_MASK
         | SPI_SR_RFDF_MASK);
    
    SPI_MCR_REG(base_addr) |= SPI_MCR_CLR_TXF_MASK    /* Clear TX FIFO */
                            | SPI_MCR_CLR_RXF_MASK;   /* Clears the RX Counter */
    
    for (i = 0; i < len; i++)
    {
        if (i == (len - 1))
        {
            SPI_PUSHR_REG(base_addr) = 0 
                    | SPI_PUSHR_CTAS(0)            /* Clock and Transfer Attributes Select */
                    | SPI_PUSHR_EOQ_MASK           /* End Of Queue */
                    | SPI_PUSHR_TXDATA(data[i]);   /* Transmit Data */
        }
        else
        {
            SPI_PUSHR_REG(base_addr) = 0 
                    | SPI_PUSHR_CONT_MASK
                    | SPI_PUSHR_CTAS(0) 
                    | SPI_PUSHR_TXDATA(data[i]);
        }
    }
    
    /* 等待数据发送完毕 */
    while((SPI_SR_REG(base_addr) & SPI_SR_TCF_MASK)==0);
    SPI_SR_REG(base_addr) |= SPI_SR_TCF_MASK;
}
Ejemplo n.º 22
0
/**
 * @brief  SPI读写一字节数据
 * @code
 *     //使用SPI的1模块的1片选信号写一字节的数据0x55,片选信号最后为选中状态
 *    SPI_ReadWriteByte(HW_SPI1, HW_CTAR0, 0x55, 1, kSPI_PCS_ReturnInactive);
 * @endcode
 * @param[in]  instance      芯片SPI端口
 *              @arg HW_SPI0 芯片的SPI0端口
 *              @arg HW_SPI1 芯片的SPI1端口
 *              @arg HW_SPI2 芯片的SPI2端口
 * @param[in]  ctar SPI通信通道选择
 *          		@arg HW_CTAR0  0配置寄存器
 *          		@arg HW_CTAR1  1配置寄存器
 * @param[in]  data     要发送的一字节数据
 * @param[in]  CSn      片选信号端口选择
 * @param[in]  csState  片选信号最后的状态
 *          		@arg kSPI_PCS_ReturnInactive  最后处于选中状态
 *          		@arg kSPI_PCS_KeepAsserted    最后保持未选中状态
 * @return 读取到的数据
 */
uint16_t SPI_ReadWriteByte(uint32_t instance, uint32_t ctar, uint16_t data, uint16_t CSn, SPI_PCS_Type csState)
{
	SPI_InstanceTable[instance]->PUSHR = (((uint32_t)(((csState))<<SPI_PUSHR_CONT_SHIFT))&SPI_PUSHR_CONT_MASK) 
            | SPI_PUSHR_CTAS(ctar)      
            | SPI_PUSHR_PCS(1<<CSn)
            | SPI_PUSHR_TXDATA(data);
    
    /* waitting for complete */
    if(!(SPI_InstanceTable[instance]->RSER & SPI_RSER_TCF_RE_MASK)) /* if it is polling mode */
    {
        while(!(SPI_InstanceTable[instance]->SR & SPI_SR_TCF_MASK));
        SPI_InstanceTable[instance]->SR |= SPI_SR_TCF_MASK;
    }
    return (uint16_t)SPI_InstanceTable[instance]->POPR;
}
Ejemplo n.º 23
0
static inline void irq_handler_transfer(SPI_Type *spi, spi_t dev)
{

    if (spi->SR & SPI_SR_RFDF_MASK) {
        char data;
        data = (char)spi->POPR;
        data = spi_config[dev].cb(data);
        spi->PUSHR = SPI_PUSHR_CTAS(0)
                     | SPI_PUSHR_EOQ_MASK
                     | SPI_PUSHR_TXDATA(data);
    }

    /* see if a thread with higher priority wants to run now */
    cortexm_isr_end();
}
Ejemplo n.º 24
0
/*
 * To set the LCD register to read/write, send out 0x70 and then the register #
 */
static void SpiRegSet(unsigned char reg)
{
  unsigned short data;

  //Set the data to write out by concatenating 0x70 with the register value.
  data=0x7000 | reg;

  // wait write buffer not full flag
  while (!(SPI2_SR & SPI_SR_TFFF_MASK)){};

  // Assert CS0, Use config 0, and send out on MISO
  SPI2_PUSHR = SPI_PUSHR_PCS(1 << (0)) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_TXDATA((unsigned short)data);

  while (!(SPI2_SR & SPI_SR_TCF_MASK)){};// while shift-out complete
  SPI2_SR = SPI_SR_TCF_MASK;           // clear flag
}
Ejemplo n.º 25
0
/*
 * To write data to a LCD register, send out 0x72 and then value
 * Make sure to set the register index first via SpiRegSet()
 */
static void SpiSendDataWord(unsigned char value)
{
  unsigned short data;

  //Set the data to write out by concatenating 0x72 with the data to write
  data=0x7200 | value;

  // wait write buffer not full flag
  while (!(SPI2_SR & SPI_SR_TFFF_MASK)){};

  // Assert CS0, Use config 0
  SPI2_PUSHR = SPI_PUSHR_PCS(1 << (0)) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_TXDATA((unsigned short)data);

  while (!(SPI2_SR & SPI_SR_TCF_MASK)){};// while shift-out complete
  SPI2_SR = SPI_SR_TCF_MASK;           // clear flag
}
Ejemplo n.º 26
0
/**
 * @brief  SPI读写一字节数据
 * @code
 *     //使用SPI的1模块的1片选信号写一字节的数据0x55,片选信号最后为选中状态
 *    SPI_ReadWriteByte(HW_SPI1, HW_CTAR0, 0x55, 1, kSPI_PCS_ReturnInactive);
 * @endcode
 * @param  instance :SPI通信模块号 HW_SPI0~2
 * @param  ctar :SPI通信通道选择
 *          @arg HW_CTAR0  :0通道
 *          @arg HW_CTAR1  :1通道
 * @param  data    : 要发送的一字节数据
 * @param  CSn     : 片选信号端口选择
 * @param  csState : 片选信号最后的状态
 *          @arg kSPI_PCS_ReturnInactive  :最后处于选中状态
 *          @arg kSPI_PCS_KeepAsserted    :最后保持未选中状态
 * @retval 读取到的数据
 */
uint16_t SPI_ReadWriteByte(uint32_t instance,uint32_t ctar, uint16_t data, uint16_t CSn, uint16_t csState)
{
    uint16_t read_data;
	SPI_InstanceTable[instance]->PUSHR = (((uint32_t)(((csState))<<SPI_PUSHR_CONT_SHIFT))&SPI_PUSHR_CONT_MASK) 
            | SPI_PUSHR_CTAS(ctar)      
            | SPI_PUSHR_PCS(1<<CSn)
            | SPI_PUSHR_TXDATA(data);
    if(!(SPI_InstanceTable[instance]->RSER & SPI_RSER_TCF_RE_MASK)) // if it is polling mode
    {
        /* wait for transfer complete */
        while(!(SPI_InstanceTable[instance]->SR & SPI_SR_TCF_MASK)){};
        /* clear flag */
        SPI_InstanceTable[instance]->SR |= SPI_SR_TCF_MASK;
    }
    read_data = (uint16_t)SPI_InstanceTable[instance]->POPR;
    return read_data;
}
Ejemplo n.º 27
0
void Adafruit_HX8357::spiwrite(uint8_t c) {

  Serial.print("0x"); Serial.print(c, HEX); Serial.print(", ");

  if (hwSPI) {
#if defined (__AVR__)
    uint8_t backupSPCR = SPCR;
    SPCR = mySPCR;
    SPDR = c;
    while(!(SPSR & _BV(SPIF)));
    SPCR = backupSPCR;
#elif defined(__MK20DX128__) || defined(__MK20DX256__)
   /* for(uint8_t bit = 0x80; bit; bit >>= 1) {
      if(c & bit) {
	//digitalWrite(_mosi, HIGH); 
	*mosiport |=  mosipinmask;
      } else {
	//digitalWrite(_mosi, LOW); 
	*mosiport &= ~mosipinmask;
      }
      //digitalWrite(_sclk, HIGH);
      *clkport |=  clkpinmask;
      //digitalWrite(_sclk, LOW);
      *clkport &= ~clkpinmask;
    }   */
   Serial.println("in teensy spiwrite"); 
   	if (hwSPI) {
		SPI0.PUSHR = c | (pcs_data << 16) | SPI_PUSHR_CTAS(0);
		while (((SPI0.SR) & (15 << 12)) > (3 << 12)) ; // wait if FIFO full
	}else{ 	
   for (uint8_t bit = 0x80; bit; bit >>= 1) {
		*mosiport = ((c & bit) ? 1 : 0);
		*clkport = 1;
		*clkport = 0;
	}}
	Serial.println("finished teensy spiwrite");
#elif defined (__arm__)
    SPI.setClockDivider(11); // 8-ish MHz (full! speed!)
    SPI.setBitOrder(MSBFIRST);
    SPI.setDataMode(SPI_MODE0);
    SPI.transfer(c);
#endif
  } else {
    // Fast SPI bitbang swiped from LPD8806 library
    for(uint8_t bit = 0x80; bit; bit >>= 1) {
Ejemplo n.º 28
0
INT8U SPI_SendReceive ( SPI_Type *SPIx, INT8U tx_dat )
{
	SPIx->SR	 = (SPI_SR_EOQF_MASK	|
				SPI_SR_TFFF_MASK	|
				SPI_SR_TFUF_MASK	|
				SPI_SR_RFDF_MASK	|
				SPI_SR_RFOF_MASK	);
	
	SPIx->MCR |= (SPI_MCR_CLR_RXF_MASK|
				SPI_MCR_CLR_TXF_MASK);	
		
	SPIx->PUSHR = (SPI_PUSHR_CTAS(0)	|
				SPI_PUSHR_EOQ_MASK	|
				SPI_PUSHR_PCS(1)	|	/*SPI Flash cs Conflict with lcd_en(pcs1) spiflash need comment this statement*/
				SPI_PUSHR_TXDATA(tx_dat));
		
 	while((SPIx->SR & SPI_SR_TCF_MASK) == 0);
	SPIx->SR |= SPI_SR_TCF_MASK;
	
	return (SPIx->POPR);
}
Ejemplo n.º 29
0
/*********************************************************
* Name: SPI_Receive_byte
* Desc: The byte received by SPI  
* Parameter: None
* Return: Received byte
**********************************************************/
uint_8 SPI_Receive_byte(void)
{
    uint_16 u8Data;
    
    /*Body*/        
    /* Check the status flag */
    if(SPI1_SR & SPI_SR_EOQF_MASK)
    {
        /* Clear the EOQF by writting a 1 to it */
        SPI1_SR |= SPI_SR_EOQF_MASK;
    }/*EndIf*/
    
    /* Write the DSPI_PUSHR register */
    SPI1_PUSHR = (  SPI_PUSHR_CTAS(0)       | 
                    SPI_PUSHR_EOQ_MASK      |
                    SPI_PUSHR_CTCNT_MASK    |
                    SPI_PUSHR_PCS(1)        |
                    SPI_PUSHR_TXDATA(0xFF)); 
    /* Write the clock and transfer attributes: master clock and frame size (8 bits) */
    SPI1_CTAR0 = (  SPI_CTAR_FMSZ(7)            | 
                    gSPI_BeforeTransfDelay      |
                    gSPI_AfterTransfDelay       |
                    gSPI_InterTransfDelay       |
                    gSPI_BaudRate);       
        
    /* Start the transfer */
    SPI1_MCR &= ~SPI_MCR_HALT_MASK;
    /* Wait until the transfer has been finished */
    while(!(SPI1_SR & SPI_SR_EOQF_MASK))
    {
        Watchdog_Reset();
    }/*EndWhile*/
    /* Clear the EOQF by writting a 1 to it */
    SPI1_SR |= SPI_SR_EOQF_MASK;
    /* Read the byte form the DSPI_POPR register */
    u8Data = (uint_16)SPI_RXFR0_RXDATA(SPI1_POPR);
        
    return((uint_8)u8Data);
}/*EndBody*/
Ejemplo n.º 30
0
OSStatus spi_init( spi_driver_t* spi_driver, SPI_MemMapPtr spi_peripheral, uint32_t baud_rate_bps, uint8_t chip_select, bool polarity, bool phase, bool use_dma )
{
    uint8_t br = get_baud_rate_scaler_register_value( baud_rate_bps );

    spi_driver->spi_peripheral = spi_peripheral;
    spi_driver->baud_rate_bps  = baud_rate_bps;
    spi_driver->chip_select    = chip_select;
    spi_driver->polarity       = polarity;
    spi_driver->phase          = phase;
    spi_driver->use_dma        = use_dma;

    /* Enable SPI peripheral clock */
    set_spi_peripheral_clock( spi_peripheral, true );

    /* Enable SPI peripheral and clean up (stop) any previous transfer
     * MDIS     = 0 to enable
     * HALT     = 1 to stop transfer
     * MSTR     = 1 for master mode
     * DCONF    = 0 for SPI
     * PCSIS[x] = 1 for CS active low
     */
    SPI_MCR_REG( spi_peripheral ) &= ~(uint32_t) ( SPI_MCR_MDIS_MASK | SPI_MCR_DCONF(0) );
    SPI_MCR_REG( spi_peripheral ) |=  (uint32_t) ( (0x1<<24)|SPI_MCR_HALT_MASK | SPI_MCR_MSTR_MASK | SPI_MCR_PCSIS( 1 << chip_select ) );

    /* Select Clock and Transfer Attributes Register (CTAR). Always use CTAR0 */
    SPI_PUSHR_REG( spi_peripheral ) &= ~(uint32_t) SPI_PUSHR_CTAS(CTAR_REG_USED);

    /* Reset Clock and Transfer Attributes (CTAR) register */
    SPI_CTAR_REG( spi_peripheral, CTAR_REG_USED ) = 0;

    /* Set SPI configuration
     * FMSZ   = 7. Set frame size to 8-bit. frame size = FMSZ + 1
     * CPOL   = phase
     * CPHA   = polarity
     * DBR    = 00
     * PBR    = 2
     * BR     = calculate based on baud_rate_Mbps
     * PCSSCK = 0
     * PASC   = 0
     * PDT    = 0
     * CSSCK  = BR - 1
     * ASC    = BR - 1
     * DT     = 0
     */
    SPI_CTAR_REG( spi_peripheral, CTAR_REG_USED ) |= (uint32_t) ( SPI_CTAR_CPOL_MASK & (uint32_t)( polarity << SPI_CTAR_CPOL_SHIFT ) ) |
                                                     (uint32_t) ( SPI_CTAR_CPHA_MASK & (uint32_t)( phase    << SPI_CTAR_CPHA_SHIFT ) ) |
                                                     (uint32_t) ( SPI_CTAR_FMSZ( 8 - 1 ) ) |
                                                     (uint32_t) ( SPI_CTAR_DBR_MASK & ( DOUBLE_BAUD_RATE << SPI_CTAR_DBR_SHIFT ) ) |
                                                     (uint32_t) ( SPI_CTAR_PBR( CTAR_PBR ) ) |
                                                     (uint32_t) ( SPI_CTAR_BR( br ) ) |
                                                     (uint32_t) ( SPI_CTAR_CSSCK( br - 1 ) ) |
                                                     (uint32_t) ( SPI_CTAR_ASC( br - 1 ) );

    clear_spi_fifos( spi_peripheral );
        
    /* Enable the start transfer bit */
    SPI_MCR_REG( spi_peripheral ) &= ~(uint32_t) ( SPI_MCR_HALT_MASK );

	if(use_dma)
	{
		SPI_RSER_REG( spi_peripheral ) |= (0x3<<24)|(0x3<<16);
		DMA_init();
	}

    spi_status_print(spi_peripheral);
    return kNoErr;
}