C6748 SPI通信 - TMS320C6748 - 嵌入式开发者社区 - 51ele.net
设为首页收藏本站

嵌入式开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 5749|回复: 3

C6748 SPI通信

[复制链接]

1

主题

2

帖子

19

积分

新手上路

Rank: 1

积分
19
发表于 2014-7-30 22:48:43 | 显示全部楼层 |阅读模式
新买的入门C6748开发板,C6748做为主机通过SPI与外部设备通信,使用的是SPI0,使用的是TI官方的SPI例程(只是将SPI1改成了SPI0,CS使用CS0),非内环测试,接收和发送中断都触发了,但是引脚没有数据输出,请问有没有类似的例程给参考一下

回复

使用道具 举报

2

主题

50

帖子

502

积分

版主

Rank: 7Rank: 7Rank: 7

积分
502
发表于 2014-7-31 08:21:58 | 显示全部楼层
你的管脚复用PINMUX设置了吗
回复 支持 反对

使用道具 举报

1

主题

2

帖子

19

积分

新手上路

Rank: 1

积分
19
 楼主| 发表于 2014-7-31 08:48:46 | 显示全部楼层
weibo1988821 发表于 2014-7-31 08:21
你的管脚复用PINMUX设置了吗

管脚该怎么复用啊,代码里面是这样的

    /* Performing the Pin Multiplexing for SPI0. */
    SPIPinMuxSetup(0);

求指点


#include <string.h>
#include "soc_C6748.h"
#include "hw_psc_C6748.h"
#include "lcdkC6748.h"
#include "uart.h"
#include "spi.h"
#include "psc.h"
#include "interrupt.h"
#include "uartStdio.h"

/******************************************************************************
**                      INTERNAL MACRO DEFINITIONS
*******************************************************************************/
/* value to configure SMIO,SOMI,CLK and CS pin as functional pin */
#define SIMO_SOMI_CLK_CS        0x00000E01
#define CHAR_LENGTH             0x8

/******************************************************************************
**                      INTERNAL FUNCTION PROTOTYPES
*******************************************************************************/
static void SPIConfigDataFmtReg(unsigned int dataFormat);
static void SpiTransfer(void);
static void SetUpInt(void);
static void SetUpSPI(void);
static void GetStatusCommand(void);
static void ResetCommand(void);
void SPIIsr(void);

/******************************************************************************
**                      INTERNAL VARIABLE DEFINITIONS
*******************************************************************************/
volatile unsigned int flag = 1;
unsigned int tx_len;
unsigned int rx_len;
unsigned char vrf_data[260];
unsigned char tx_data[260];
volatile unsigned char rx_data[260];
unsigned char *p_tx;
volatile unsigned char *p_rx;
volatile unsigned char StatusResponseMessage[16];

/******************************************************************************
**                      INTERNAL FUNCTION DEFINITIONS
*******************************************************************************/
int main(void)
{
    /* Waking up the SPI1 instance. */
    PSCModuleControl(SOC_PSC_0_REGS, HW_PSC_SPI0, PSC_POWERDOMAIN_ALWAYS_ON,
                     PSC_MDCTL_NEXT_ENABLE);

    /* Initializing the UART instance for serial communication. */
    UARTStdioInit();

    UARTPuts("Welcome to StarterWare SPI application.\r\n\r\n", -1);
    UARTPuts("Here the SPI controller on the SoC communicates with", -1);
    UARTPuts(" the Fingerprint Sensor present on the LCDK.\r\n\r\n", -1);

    /* Performing the Pin Multiplexing for SPI0. */
    SPIPinMuxSetup(0);

    /*
    ** Using the Chip Select(CS) 0 pin of SPI0 to communicate with the Fingerprint Sensor.
    */
    SPI0CSPinMuxSetup(0);


    /* Enable use of SPI1 interrupts. */
    SetUpInt();

    /* Configuring and enabling the SPI1 instance. */
    SetUpSPI();

    /* Issue a Reset to the Fingerprint Sensor */
//    ResetCommand();
//    UARTPuts("Attempting to Reset the Fingerprint Sensor.\r\n\r\n", -1);
//
//    /* Read the Status of the Fingerprint Sensor */
//    GetStatusCommand();
//    if(StatusResponseMessage[11] == 0x48)
//    {
//        UARTPuts("Fingerprint Sensor Successfully Reset.\r\n\r\n", -1);
//    }
//    else
//    {
//        UARTPuts("ERROR: Fingerprint Sensor Reset Attempt Unsuccessful.\r\n\r\n", -1);
//    }

        tx_data[0] = 0x00;
        tx_data[1] = 0x01;
        tx_data[2] = 0x02;
        tx_data[3] = 0x03;
        tx_data[4] = 0x04;
        tx_data[5] = 0x05;
        tx_data[6] = 0x06;
        tx_data[7] = 0x07;
        tx_data[8] = 0x08;
        tx_data[9] = 0x09;
        tx_data[10] = 0x0a;
        tx_data[11] = 0x0b;
        tx_data[12] = 0x0c;
        tx_data[13] = 0x0d;
        tx_data[14] = 0x0e;
        tx_data[15] = 0x0f;
        tx_data[16] = 0x10;
        tx_data[17] = 0x11;
        tx_data[18] = 0x12;
        tx_data[19] = 0x13;
        tx_data[20] = 0x14;
        tx_data[21] = 0x15;
        tx_data[22] = 0x16;

        tx_len = 23;
        rx_len = 23;

    for(;;)
    {
            SpiTransfer();
//            for(; i<100000; i++);
    }
}

/*
** Configures ARM interrupt controller to generate SPI interrupt
**
*/
static void SetUpInt(void)
{
        // Setup the ARM or DSP interrupt controller

#ifdef _TMS320C6X
        // Initialize the DSP interrupt controller
        IntDSPINTCInit();

        // Register the ISR in the vector table
        IntRegister(C674X_MASK_INT4, SPIIsr);

        // Map system interrupt to the DSP maskable interrupt
        IntEventMap(C674X_MASK_INT4, SYS_INT_SPI0_INT);

        // Enable the DSP maskable interrupt
        IntEnable(C674X_MASK_INT4);

        IntEventSet(SYS_INT_SPI0_INT);

        // Enable DSP interrupts globally
        IntGlobalEnable();
#else
    /* Initialize the ARM Interrupt Controller.*/
    IntAINTCInit();

    /* Register the ISR in the Interrupt Vector Table.*/
    IntRegister(SYS_INT_SPINT1, SPIIsr);

    /* Set the channnel number 2 of AINTC for system interrupt 56.
     * Channel 2 is mapped to IRQ interrupt of ARM9.
    */
    IntChannelSet(SYS_INT_SPINT1, 2);

    /* Enable the System Interrupts for AINTC.*/
    IntSystemEnable(SYS_INT_SPINT1);

    /* Enable IRQ in CPSR.*/
    IntMasterIRQEnable();

    /* Enable the interrupts in GER of AINTC.*/
    IntGlobalEnable();

    /* Enable the interrupts in HIER of AINTC.*/
    IntIRQEnable();
#endif
}



//** Configures SPI Controller
static void SetUpSPI(void)
{
        unsigned char cs = 0x01;//0x04;******************
        unsigned char dcs = 0x01;//0x04;******************
        unsigned int val = SIMO_SOMI_CLK_CS;
        SPIReset(SOC_SPI_0_REGS);

        SPIOutOfReset(SOC_SPI_0_REGS);

        SPIModeConfigure(SOC_SPI_0_REGS, SPI_MASTER_MODE);

        SPIClkConfigure(SOC_SPI_0_REGS, 150000000, 1000000, SPI_DATA_FORMAT0);//SCLK原为1M

        SPIPinControl(SOC_SPI_0_REGS, 0, 0, &val);

        SPIDefaultCSSet(SOC_SPI_0_REGS, dcs);

        /* Configures SPI Data Format Register */
        SPIConfigDataFmtReg(SPI_DATA_FORMAT0);

        /* Selects the SPI Data format register to used and Sets CSHOLD
        * to assert CS pin(line)
        */
        SPIDat1Config(SOC_SPI_0_REGS, (SPI_CSHOLD | SPI_DATA_FORMAT0), cs);

        /* map interrupts to interrupt line INT1 */
        SPIIntLevelSet(SOC_SPI_0_REGS, SPI_RECV_INTLVL | SPI_TRANSMIT_INTLVL);

        /* Enable SPI communication */
        SPIEnable(SOC_SPI_0_REGS);
}
//** Configures Data Format register of SPI
static void SPIConfigDataFmtReg(unsigned int dataFormat)
{
        /* Configures the polarity and phase of SPI clock */
        SPIConfigClkFormat(SOC_SPI_0_REGS,(SPI_CLK_POL_HIGH | SPI_CLK_INPHASE),dataFormat);//SPI_CLK_POL_HIGH SPI_CLK_OUTOFPHASE
        //SPIConfigClkFormat(SOC_SPI_0_REGS,(SPI_CLK_POL_LOW | SPI_CLK_INPHASE),dataFormat);

        /* Configures SPI to transmit MSB bit First during data transfer */
        SPIShiftMsbFirst(SOC_SPI_0_REGS, dataFormat);

        /* Sets the Charcter length */
        SPICharLengthSet(SOC_SPI_0_REGS, CHAR_LENGTH, dataFormat);
}

//** Enables SPI Transmit and Receive interrupt.** Deasserts Chip Select line.
static void SpiTransfer(void)
{
        p_tx = &tx_data[0];
        p_rx = &rx_data[0];

        SPIIntEnable(SOC_SPI_0_REGS, (SPI_RECV_INT | SPI_TRANSMIT_INT));
//        while(flag);
//        flag = 1;
        /* Deasserts the CS pin(line) */
        SPIDat1Config(SOC_SPI_0_REGS, SPI_DATA_FORMAT0, 0x01);
}

//** Data transmission and receiption SPIIsr
void SPIIsr(void)
{
        unsigned int intCode = 0;

        IntEventClear(SYS_INT_SPI0_INT);

        intCode = SPIInterruptVectorGet(SOC_SPI_0_REGS);

        while (intCode)
        {

                if(intCode == SPI_TX_BUF_EMPTY)
                {
                        tx_len--;
                        SPITransmitData1(SOC_SPI_0_REGS, *p_tx);
                        p_tx++;
                        if (!tx_len)
                        {
                                tx_len = 23;
                                SPIIntDisable(SOC_SPI_0_REGS, SPI_TRANSMIT_INT);
                                break;
                        }
                }

        if(intCode == SPI_RECV_FULL)
        {
            rx_len--;
            *p_rx = (char)SPIDataReceive(SOC_SPI_0_REGS);
            p_rx++;
            if (!rx_len)
            {
                flag = 0;
                SPIIntDisable(SOC_SPI_0_REGS, SPI_RECV_INT);
            }
        }

        intCode = SPIInterruptVectorGet(SOC_SPI_0_REGS);
        }
}
回复 支持 反对

使用道具 举报

15

主题

1357

帖子

4579

积分

创龙

Rank: 8Rank: 8

积分
4579
发表于 2014-8-8 12:11:51 | 显示全部楼层
SPI 管脚复用除了SPI的还得配置SPI片选的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|嵌入式开发者社区 ( 粤ICP备15055271号

GMT+8, 2024-3-28 20:55 , Processed in 0.043606 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2015 Comsenz Inc.

快速回复 返回顶部 返回列表