TI中文支持网
TI专业的中文技术问题搜集分享网站

tms570lc4357 的spi4 操作ais328dq 模块

SPI4 是MIBSPI4 的一种简化模式,配置时使用SPI模式,片选贤使用的是CS[1]、时钟设置的500K,16bit,polarity =1,phase =0;其他值默认。

采用下面的程序读取ais328dq 芯片 设备寄存器WHO_AM_I register 的值(手册上为0x32),但读取的结果 receiveData = 0xFFFF。

 spiInit();

spiDAT1_t dataConfig ={0,0,SPI_FMT_0,SPI_CS_1};

 sendData =0x8f00;
  spiTransmitAndReceiveData(spiREG4, &dataConfig, 1,&sendData, &receiveData);

我想请教上面的程序操作是否对?有没有关于这个模块的使用例子。

Susan Yang:

您可以尝试参考下面的代码

MIBSPI1用于将数据发送到SPI4(必须进行外部连接)
MIBSPI1使用DMA将数据从RAM传输到MIBSPI RAM进行传输。
SPI4接收DATA,中断用于读取传入的数据并移至RAM
SPI4在接收后使用DMA将数据从MIBSPI RAM移至RAM,然后将数据发送至MIBSPI1(也使用中断)。

您可以专注于SPI4代码以查看如何管理中断。

4331.TMS570LS1224_MIPSPI1_SPI4_DMA.zip

,

Susan Yang:

另外也可以参考下面的代码

/** @file example_SPI_Master_Slave.c
*@brief Application main file
*@date 25.July.2013
*@version 03.06.00
*
*This file contains an example of SPI1 and SPI2 Master / Slave configurations.
*
*PIN Connections must be as Below
*------------------------------
*SPI1 ( Master )SPI2 ( SLave)
*------------------------------
*SIM0--->SIMO
*S0MI<---SOMI
*CLK--->CLK
*CS0--->CS0
*
*------------------
*GUI configurations
*------------------
*1) Driver TAB
*- Select SPI2
*- Select SPI1
*2) VIm Channel 0-31
*- Enable SPI2 Level 0 and Level 1 channels.
*3) SPI2 TAB
*- SPI2 Global SubTAB
*- Uncheck Master Mode
*- Uncheck Internal Clock
*- SPI2 Port SubTAB
*- Uncheck DIR for CS 0
*3) SPI1 TAB
*- Have it default
*4) Generate Code.
*
*//* (c) Texas Instruments 2009-2013, All rights reserved. *//** Copyright (C) 2009-2015 Texas Instruments Incorporated - www.ti.com
***Redistribution and use in source and binary forms, with or without*modification, are permitted provided that the following conditions*are met:
*
*Redistributions of source code must retain the above copyright*notice, this list of conditions and the following disclaimer.
*
*Redistributions in binary form must reproduce the above copyright
*notice, this list of conditions and the following disclaimer in the*documentation and/or other materials provided with the*distribution.
*
*Neither the name of Texas Instruments Incorporated nor the names of
*its contributors may be used to endorse or promote products derived
*from this software without specific prior written permission.
*
*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS*"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT*LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
*A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT*OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,*SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT*LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
*DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON ANY
*THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT*INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE*OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*//* USER CODE BEGIN (0) */
/* USER CODE END *//* Include Files */#include "sys_common.h"
#include "system.h"/* USER CODE BEGIN (1) */
#include "spi.h"
/* USER CODE END *//** @fn void main(void)
*@brief Application main function
*@note This function is empty by default.
*
*This function is called after startup.
*The user can use this function to implement the application.
*//* USER CODE BEGIN (2) */
uint16 TX_Data_Master[16] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 };
uint16 TX_Data_Slave[16]= { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20 };
uint16 RX_Data_Master[16] = { 0 };
uint16 RX_Data_Slave[16]= { 0 };
/* USER CODE END */void main(void)
{
/* USER CODE BEGIN (3) */spiDAT1_t dataconfig1_t;dataconfig1_t.CS_HOLD = FALSE;dataconfig1_t.WDEL= TRUE;dataconfig1_t.DFSEL= SPI_FMT_0;dataconfig1_t.CSNR= 0xFE;/* Enable CPU Interrupt through CPSR */_enable_IRQ();/* Initialize SPI Module Based on GUI configuration* SPI1 - Master ( SIMO, SOMI, CLK, CS0 )* SPI2 - Slave( SIMO, SOMI, CLK, CS0 )* */spiInit();/* Initiate SPI2 Transmit and Receive through Interrupt Mode */spiSendAndGetData(spiREG2, &dataconfig1_t, 16, TX_Data_Slave, RX_Data_Slave);/* Initiate SPI1 Transmit and Receive through Polling Mode*/spiTransmitAndReceiveData(spiREG1, &dataconfig1_t, 16, TX_Data_Master, RX_Data_Master);while(1);
/* USER CODE END */
}/* USER CODE BEGIN (4) */
/* USER CODE END */

赞(0)
未经允许不得转载:TI中文支持网 » tms570lc4357 的spi4 操作ais328dq 模块
分享到: 更多 (0)