完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,现在做一个129x slave spi mode的项目,能否提供下参考代码,谢谢!
我的代码未调通,如下: SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2); //Enable SSI2 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //Enable GPIOD GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_2); //CS //SSI2CSH; GPIOPinConfigure(GPIO_PD3_SSI2CLK); GPIOPinConfigure(GPIO_PD1_SSI2XDAT0);//SSI2TX GPIOPinConfigure(GPIO_PD0_SSI2XDAT1);//SSI2RX //GPIOPinTypeSSI(GPIO_PORTB_BASE, GPIO_PIN_5); GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3); SSIConfigSetExpClk(SSI2_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_2, SSI_MODE_SLAVE, 800000, 8); SSIEnable(SSI2_BASE); |
|
相关推荐
9 个讨论
|
|
你用的是四线SPI吧,怎么初始化了三条线呢,给你看看官方的例程的初始化步骤
//*****************************************************************************//// spi_master.c - Example demonstrating how to configure SSI0 in SPI master// mode.//// Copyright (c) 2010-2014 Texas Instruments Incorporated. All rights reserved.// Software License Agreement// // 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.// // This is part of revision 2.1.0.12573 of the Tiva Firmware Development Package.////*****************************************************************************#include SPI Master (spi_master)//!//! This example shows how to configure the SSI0 as SPI Master. The code will//! send three characters on the master Tx then polls the receive FIFO until//! 3 characters are received on the master Rx.//!//! This example uses the following peripherals and I/O signals. You must//! review these and change as needed for your own board://! - SSI0 peripheral//! - GPIO Port A peripheral (for SSI0 pins)//! - SSI0Clk - PA2//! - SSI0Fss - PA3//! - SSI0Rx - PA4//! - SSI0Tx - PA5//!//! The following UART signals are configured only for displaying console//! messages for this example. These are not required for operation of SSI0.//! - UART0 peripheral//! - GPIO Port A peripheral (for UART0 pins)//! - UART0RX - PA0//! - UART0TX - PA1//!//! This example uses the following interrupt handlers. To use this example//! in your own application you must add these interrupt handlers to your//! vector table.//! - None.////*****************************************************************************//*****************************************************************************//// Number of bytes to send and receive.////*****************************************************************************#define NUM_SSI_DATA 3//*****************************************************************************//// This function sets up UART0 to be used for a console to display information// as the example is running.////*****************************************************************************voidInitConsole(void)[ // // Enable GPIO port A which is used for UART0 pins. // TODO: change this to whichever GPIO port you are using. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Configure the pin muxing for UART0 functions on port A0 and A1. // This step is not necessary if your part does not support pin muxing. // TODO: change this to select the port/pin you are using. // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); // // Enable UART0 so that we can configure the clock. // SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // // Use the internal 16MHz oscillator as the UART clock source. // UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); // // Select the alternate (UART) function for these pins. // TODO: change this to select the port/pin you are using. // GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Initialize the UART for console I/O. // UARTStdioConfig(0, 115200, 16000000);]//*****************************************************************************//// Configure SSI0 in master Freescale (SPI) mode. This example will send out// 3 bytes of data, then wait for 3 bytes of data to come in. This will all be// done using the polling method.////*****************************************************************************intmain(void)[ uint32_t pui32DataTx[NUM_SSI_DATA]; uint32_t pui32DataRx[NUM_SSI_DATA]; uint32_t ui32Index; // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for SSI operation. // InitConsole(); // // Display the setup on the console. // UARTprintf("SSI ->n"); UARTprintf(" Mode: SPIn"); UARTprintf(" Data: 8-bitnn"); // // The SSI0 peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); // // For this example SSI0 is used with PortA[5:2]. The actual port and pins // used may be different on your part, consult the data sheet for more // information. GPIO port A needs to be enabled so these pins can be used. // TODO: change this to whichever GPIO port you are using. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Configure the pin muxing for SSI0 functions on port A2, A3, A4, and A5. // This step is not necessary if your part does not support pin muxing. // TODO: change this to select the port/pin you are using. // GPIOPinConfigure(GPIO_PA2_SSI0CLK); GPIOPinConfigure(GPIO_PA3_SSI0FSS); GPIOPinConfigure(GPIO_PA4_SSI0RX); GPIOPinConfigure(GPIO_PA5_SSI0TX); // // Configure the GPIO settings for the SSI pins. This function also gives // control of these pins to the SSI hardware. Consult the data sheet to // see which functions are allocated per pin. // The pins are assigned as follows: // PA5 - SSI0Tx // PA4 - SSI0Rx // PA3 - SSI0Fss // PA2 - SSI0CLK // TODO: change this to select the port/pin you are using. // GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 | GPIO_PIN_2); // // Configure and enable the SSI port for SPI master mode. Use SSI0, // system clock supply, idle clock level low and active low clock in // freescale SPI mode, master mode, 1MHz SSI frequency, and 8-bit data. // For SPI mode, you can set the polarity of the SSI clock when the SSI // unit is idle. You can also configure what clock edge you want to // capture data on. Please reference the datasheet for more information on // the different SPI modes. // SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 1000000, 8); // // Enable the SSI0 module. // SSIEnable(SSI0_BASE); // // Read any residual data from the SSI port. This makes sure the receive // FIFOs are empty, so we don't read any unwanted junk. This is done here // because the SPI SSI mode is full-duplex, which allows you to send and // receive at the same time. The SSIDataGetNonBlocking function returns // "true" when data was returned, and "false" when no data was returned. // The "non-blocking" function checks if there is any data in the receive // FIFO and does not "hang" if there isn't. // while(SSIDataGetNonBlocking(SSI0_BASE, &pui32DataRx[0])) [ ] // // Initialize the data to send. // pui32DataTx[0] = 's'; pui32DataTx[1] = 'p'; pui32DataTx[2] = 'i'; // // Display indication that the SSI is transmitting data. // UARTprintf("Sent:n "); // // Send 3 bytes of data. // for(ui32Index = 0; ui32Index < NUM_SSI_DATA; ui32Index++) [ // // Display the data that SSI is transferring. // UARTprintf("'%c' ", pui32DataTx[ui32Index]); // // Send the data using the "blocking" put function. This function // will wait until there is room in the send FIFO before returning. // This allows you to assure that all the data you send makes it into // the send FIFO. // SSIDataPut(SSI0_BASE, pui32DataTx[ui32Index]); ] // // Wait until SSI0 is done transferring all the data in the transmit FIFO. // while(SSIBusy(SSI0_BASE)) [ ] // // Display indication that the SSI is receiving data. // UARTprintf("nReceived:n "); // // Receive 3 bytes of data. // for(ui32Index = 0; ui32Index < NUM_SSI_DATA; ui32Index++) [ // // Receive the data using the "blocking" Get function. This function // will wait until there is data in the receive FIFO before returning. // SSIDataGet(SSI0_BASE, &pui32DataRx[ui32Index]); // // Since we are using 8-bit data, mask off the MSB. // pui32DataRx[ui32Index] &= 0x00FF; // // Display the data that SSI0 received. // UARTprintf("'%c' ", pui32DataRx[ui32Index]); ] // // Return no errors // return(0);] |
|
|
|
|
|
只有小组成员才能发言,加入小组>>
NA555DR VCC最低电压需要在5V供电,为什么用3.3V供电搭了个单稳态触发器也使用正常?
683 浏览 3 评论
MSP430F249TPMR出现高温存储后失效了的情况,怎么解决?
599 浏览 1 评论
对于多级放大电路板,在PCB布局中,电源摆放的位置应该注意什么?
1054 浏览 1 评论
739 浏览 0 评论
普中科技F28335开发板每次上电复位后数码管都会显示,如何熄灭它?
524 浏览 1 评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
161浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
125浏览 14评论
在使用3254进行录音的时候出现一个奇怪的现象,右声道有吱吱声,请教一下,是否是什么寄存器设置存在问题?
126浏览 13评论
TLV320芯片内部自带数字滤波功能,请问linein进来的模拟信号是否是先经过ADC的超采样?
122浏览 12评论
TPA6304-Q1: TPA6304 两片公用一组I2C的话,其中一片配置不成功怎么办
168浏览 10评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 22:25 , Processed in 0.905309 second(s), Total 61, Slave 54 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号