使用spi的例程,spi0使用IOID_2作为csn时,cs没有信号,使用IOID6的时候,信号是正常的,这个是什么原因导致的啊
#define CC1310_LAUNCHXL_SPI0_CSN IOID_2
CC1310_LAUNCHXL_SPI0_CSN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED,
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
下面是我的配置代码,你说的回传的handle是对的吗?这个怎么理解?这个handle不就是初始化的时候的handle?
管脚配置
/* SPI Flash CS*/
CC1310_LAUNCHXL_SPI0_CSN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED,
/* SPI Flash CLK */
CC1310_LAUNCHXL_SPI0_CLK | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED,
/* SPI Flash MOSI */
CC1310_LAUNCHXL_SPI0_MOSI | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_INPUT_DIS | PIN_DRVSTR_MED,
/* SPI Flash MISO */
CC1310_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN,
SPIO设置
const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC1310_LAUNCHXL_SPICOUNT] = {
{
.baseAddr = SSI0_BASE,
.intNum = INT_SSI0_COMB,
.intPriority = ~0,
.swiPriority = 0,
.powerMngrId = PowerCC26XX_PERIPH_SSI0,
.defaultTxBufValue = 0xFF,
.rxChannelBitMask = 1<<UDMA_CHAN_SSI0_RX,
.txChannelBitMask = 1<<UDMA_CHAN_SSI0_TX,
.mosiPin = CC1310_LAUNCHXL_SPI0_MOSI,
.misoPin = CC1310_LAUNCHXL_SPI0_MISO,
.clkPin = CC1310_LAUNCHXL_SPI0_CLK,
.csnPin = CC1310_LAUNCHXL_SPI0_CSN,
.minDmaTransferSize = 10
},
SPI实例
SPI_Handle spi;
SPI_init();
SPI_Params spi_params;
SPI_Params_init(&spi_params);
// spi_params.transferMode = SPI_MODE_BLOCKING;
spi_params.dataSize = 8;
spi_params.mode = SPI_MASTER;
spi_params.frameFormat = SPI_POL0_PHA0;
spi_params.bitRate = 4000000;
spi = SPI_open(Board_SPI0, &spi_params);
if (spi == NULL)
{
while (1);
}
uart 是被我注释掉的,按理说应该不影响吧?
/*
* =============================== UART ===============================
*/
//#include <ti/drivers/UART.h>
//#include <ti/drivers/uart/UARTCC26XX.h>
//
//UARTCC26XX_Object uartCC26XXObjects[CC1310_LAUNCHXL_UARTCOUNT];
//
//uint8_t uartCC26XXRingBuffer[CC1310_LAUNCHXL_UARTCOUNT][32];
//
//const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC1310_LAUNCHXL_UARTCOUNT] = {
// {
// .baseAddr = UART0_BASE,
// .powerMngrId = PowerCC26XX_PERIPH_UART0,
// .intNum = INT_UART0_COMB,
// .intPriority = ~0,
// .swiPriority = 0,
// .txPin = CC1310_LAUNCHXL_UART_TX,
// .rxPin = CC1310_LAUNCHXL_UART_RX,
// .ctsPin = PIN_UNASSIGNED,
// .rtsPin = PIN_UNASSIGNED,
// .ringBufPtr = uartCC26XXRingBuffer[CC1310_LAUNCHXL_UART0],
// .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1310_LAUNCHXL_UART0]),
// .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8,
// .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8,
// .errorFxn = NULL
// }
//};
//
//const UART_Config UART_config[CC1310_LAUNCHXL_UARTCOUNT] = {
// {
// .fxnTablePtr = &UARTCC26XX_fxnTable,
// .object = &uartCC26XXObjects[CC1310_LAUNCHXL_UART0],
// .hwAttrs = &uartCC26XXHWAttrs[CC1310_LAUNCHXL_UART0]
// },
//};
//
//const uint_least8_t UART_count = CC1310_LAUNCHXL_UARTCOUNT;
定义也是18
#define CC1310_LAUNCHXL_UART_RX IOID_19 /* RXD */
#define CC1310_LAUNCHXL_UART_TX IOID_18 /* TXD */
我用的原始的sdraw的例程,更改了mainThread,一个是Pin跟spi,但是pin已经不受控制了,
管脚的定义的话,我替换了CC1310_LAUNCHXL.H里面的
#define CC1310_LAUNCHXL_SPI0_MISO IOID_6 /* RF1.20 */
#define CC1310_LAUNCHXL_SPI0_MOSI IOID_1 /* RF1.18 */
#define CC1310_LAUNCHXL_SPI0_CLK IOID_7 /* RF1.16 */
#define CC1310_LAUNCHXL_SPI0_CSN PIN_UNASSIGNED
dsraw.c里面的更改
static PIN_Handle pinHandle;
static PIN_State pinState;
SPI_Handle asic_spi;
PIN_Config pinTable[] = {
IOID_2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_TERMINATE
};
void spi_transfer()
{
SPI_Transaction spi_transaction;
uint8_t data[3];
uint8_t tmp[3];
data[0] = 0x01;
data[1] = 0x02;
data[2] = 0x03;
spi_transaction.count = 3;
spi_transaction.txBuf = data;
spi_transaction.rxBuf = tmp;
SPI_transfer(asic_spi, &spi_transaction);
}
void *mainThread(void *arg0)
{
bool flag = 0;
GPIO_init();
pinHandle = PIN_open(&pinState, pinTable);
if (pinHandle == NULL)
{
while(1);
}
SPI_init();
SPI_Params spi_params;
SPI_Params_init(&spi_params);
// spi_params.transferMode = SPI_MODE_BLOCKING;
spi_params.dataSize = 8;
spi_params.mode = SPI_MASTER;
spi_params.frameFormat = SPI_POL0_PHA0;
spi_params.bitRate = 4000000;
asic_spi = SPI_open(Board_SPI0, &spi_params);
if (asic_spi == NULL)
{
while (1);
}
while (1)
{
PIN_setOutputValue(pinHandle, IOID_2, flag);
flag = !flag;
spi_transfer();
}
return (NULL);
}
我照你的程式修改了一下我的測試程序在我的lauchpad也是可以看到DIO_2是正常可以控制的,我的程序如下給你參考
/* Pin driver handles */ static PIN_Handle ledPinHandle; /* Global memory storage for a PIN_Config table */ static PIN_State ledPinState; /* * Initial LED pin configuration table * - LEDs Board_PIN_LED0 is on. * - LEDs Board_PIN_LED1 is off. */ PIN_Config ledPinTable[] = { 0x00000002 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, PIN_TERMINATE }; SPI_Handle masterSpi0; SPI_Params spiParams0; SPI_Handle masterSpi; SPI_Params spiParams; void spi_transfer() { SPI_Transaction spi_transaction; uint8_t data[3]; uint8_t tmp[3]; data[0] = 0x01; data[1] = 0x02; data[2] = 0x03; spi_transaction.count = 3; spi_transaction.txBuf = data; spi_transaction.rxBuf = tmp; SPI_transfer(masterSpi0, &spi_transaction); } /* * ======== mainThread ======== * Task to perform a raw write and read from the SD card. * Note: Running this application will cause any filesystem on the * SD card to become corrupted! */ uint32_t currVal = 0; void *mainThread(void *arg0) { #if 1 //GPIO_init(); ledPinHandle = PIN_open(&ledPinState, ledPinTable); if(!ledPinHandle) { /* Error initializing board LED pins */ while(1); } PIN_setOutputValue(ledPinHandle, 0x00000002, 1); #if 1 SPI_init(); /* Open SPI as master (default) */ SPI_Params_init(&spiParams0); spiParams0.frameFormat = SPI_POL0_PHA0; spiParams0.bitRate = 4000000; masterSpi0 = SPI_open(Board_SPI0, &spiParams0); if (masterSpi0 == NULL) { Display_printf(display, 0, 0, "Error initializing master SPI 0\n"); while (1); } else { Display_printf(display, 0, 0, "Master SPI 0 initialized\n"); } #endif int i; for(i=0;i<20;i++){ PIN_setOutputValue(ledPinHandle, 0x00000002, 0); currVal = PIN_getOutputValue(0x00000002); spi_transfer(); PIN_setOutputValue(ledPinHandle, 0x00000002, 1); currVal = PIN_getOutputValue(0x00000002); } return (NULL); }