Part Number:CC1310
使用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,
YiKai Chen:
查看看IOID_2有沒有被其他功能佔用
,
leo liu:
已经在[CC1310_LAUNCHXL.c]中把大部分功能都注掉了,全局搜了一下IOID_2相关的定义使用,应该是没有被其它功能占用的,有没有什么方法可以确认管脚会被占用的呢?
,
YiKai Chen:
你SPI_open回傳的handle是對的嗎?
,
leo liu:
下面是我的配置代码,你说的回传的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); }
,
YiKai Chen:
我指的是spi = SPI_open(Board_SPI0, &spi_params);這個回傳的spi handle是正常的嗎?
,
Kevin Qiu1:
DIO2在launchpad上默认被设为UART Rx,返回的handle如果不正确,再检查UART部分
,
leo liu:
这个是正常的,如果异常的话,它就不会有clk跟mosi的信号了
,
leo liu:
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 */
,
YiKai Chen:
試試把DIO2設置成GPO后去對DIO2做high/low的動作看看會不會正確執行
,
leo liu:
不会正确执行,不报异常,我用的是rfPacketErrorRate的实例
,
YiKai Chen:
如果你修改gpiointerrupt例程,把UART腳位改掉然後CONFIG_GPIO_LED_0改用DIO_2,這樣DIO_2有作用嗎?
,
leo liu:
恩,我刚用gpiointerrupt的例程,DIO2在gpiointerrupt.c里面配置为输出,然后对它进行high/low控制是正常的;但是我将它在CC1310_LAUNCHXL.H中,将它配置为csn管脚后,我开始通过spi进行数据发送,csn就一直是低,不发生变化
,
YiKai Chen:
那麼建議你設置CC1310_LAUNCHXL_SPI0_CSN 為PIN_UNASSIGNED,然後透過GPIO的方式去控制DIO_2當SPI CS腳位就好。
,
leo liu:
理解你的意思,但是当我使用了spi之后,IOID2我已经无法控制了,spi跟IOID2不能同时使用。。
,
leo liu:
刚试了下IOID2 必须跟IOID3同时控制,不然的话,IOID2就无法被控制,这感觉是跟UART有关,因为IOID2跟IOID3正好就是rx 跟tx的默认口,这个有办法关掉吗?
,
YiKai Chen:
把BOARD_DISPLAY_USE_LCD=1移掉試試
,
leo liu:
我换的gpiointerrupt的例程,没有BOARD_DISPLAY_USE_LCD=1;切到rfPacketErrorRate例程里面我也试了下,没有效果,
,
YiKai Chen:
你是用PIN_open/PIN_setOutputValue去設置IOID2的嗎?
,
leo liu:
是的,
pinHandle = PIN_open(&pinState, pinTable);
IOID_2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_setOutputValue(pinHandle, IOID_2, flag);
,
YiKai Chen:
你有檢查pinHandle是不是正確的嗎?
,
leo liu:
是正确的,不然会进到while 1的循环里面,后面的clk跟mosi不会有信号的
,
YiKai Chen:
我這邊用sdraw例程去做spi_open/PIN_open/PIN_setOutputValue,在我的launchpad上面是可以spi_open成功並控制DIO2的,應該是你的程序哪裡有問題吧
,
leo liu:
我用的原始的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);
}
,
YiKai Chen:
我照你的程式修改了一下我的測試程序在我的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_HandlemasterSpi0; SPI_ParamsspiParams0; SPI_HandlemasterSpi; SPI_ParamsspiParams;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 1SPI_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");} #endifint 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); }
,
leo liu:
你是通过creeVal来验证的吗?我是接的示波器,夹在IDIO2的管脚上看的,示波器上面没有任何变化,打断点确实是看到currVal的值是发生了变化
,
YiKai Chen:
我是接示波器来验证的,你用LaunchPad嗎?
,
leo liu:
是的,我也用的LaunchPad,但是我接的时候就是不变化的
,
YiKai Chen:
用LaunchPad要接板子上的RX pin,接DIO_2會看不到
,
leo liu:
这是什么原因啊,还有这个rx pin是在哪个位置啊?
,
YiKai Chen:
DIO_2/DIO3的印刷反了,你可以接橘色匡的RX或是接LaunchPad的DIO_3腳位(實際上是接到CC1310 DIO2)
,
leo liu:
这个。。好吧,感谢!再问一下,为什么IDIO0的管脚初始化的时候,PIN_open会失败,这是什么原因啊?
,
YiKai Chen:
PIN_open会失败通常是腳位被佔用了
,
leo liu:
IDIO0默认是哪个的管脚,我看它就是正常的IO啊,不应该会被占用,或者再在你当前的sdraw的里面,加上IOID0的设置输出,它就pin open失败了。
0x00000002 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, 0x00000000 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
,
YiKai Chen:
7×7封裝的CC1310沒有DIO_0這個腳位,你可以查一下datasheet.
,
leo liu:
好像是的,谢谢
,
Kevin Qiu1:
问题已解决,将关闭此帖,如有新问题可重开一个新帖