1.cc1310,在使用的两个spi时,一个外接传感器,一个外接sd卡,无法同时使用,使用一个时,另外一个spi打开失败
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.
static int sdspiinit(void)
{
SD_Handle sdHandle;
uint8_t result;
SD_init();
sdHandle = SD_open(Board_SD0, NULL);
if (sdHandle == NULL) {
while (1);
}
result = SD_initialize(sdHandle);
if (result != SD_STATUS_SUCCESS) {
while (1);
}
sd.handle = sdHandle;
GPIO_write(CC1310_LAUNCHXL_SPI0_CSN,0);
return 0;
}
static int memsSpiInit(void)
{
SPI_Params spiParams;
SPI_Handle memsSpiHandle;
SPI_init(); //
SPI_Params_init(&spiParams); /
spiParams.mode = SPI_MASTER;
//spiParams.bitRate = 5000000;
spiParams.bitRate = 4000000;
spiParams.dataSize = 8;
spiParams.frameFormat = SPI_POL1_PHA1;
memsSpiHandle = SPI_open(Board_SPI1, &spiParams);
if( memsSpiHandle==NULL )
{
//SPI_open() failed, Error opening SPI
SPI_close(memsSpiHandle);
return -1;
//while (1);
}
return 0;
}
前后运行这两个函数,后面的那个打开为NULL。
好的收到您提供的信息,已经跟进给工程师了,如有答复将尽快回复您。谢谢!
您好,请问下 Board_SD0 和 Board_SPI1 的定义是?
#define Board_SD0 CC1310_LAUNCHXL_SDSPI0
#define Board_SPI1 CC1310_LAUNCHXL_SPI1
#define CC1310_LAUNCHXL_SPI0_MISO IOID_14 /* RF1.20 */ //闪存SD卡对应的引脚
#define CC1310_LAUNCHXL_SPI0_MOSI IOID_15 /* RF1.18 */
#define CC1310_LAUNCHXL_SPI0_CLK IOID_10 /* RF1.16 */
#define CC1310_LAUNCHXL_SPI0_CSN IOID_11
#define CC1310_LAUNCHXL_SPI1_MISO IOID_5 //传感器对应的引脚
#define CC1310_LAUNCHXL_SPI1_MOSI IOID_6
#define CC1310_LAUNCHXL_SPI1_CLK IOID_10
#define CC1310_LAUNCHXL_SPI1_CSN IOID_4
是这样定义的,
SD_init();
sdspiinit(); //sd init
memsSpiInit(); //spi init
static int sdspiinit(void)
{
SD_Handle sdHandle;
uint8_t result;
sdHandle = SD_open(Board_SD0, NULL);
if (sdHandle == NULL) {
while (1);
}
result = SD_initialize(sdHandle);
if (result != SD_STATUS_SUCCESS) {
while (1);
}
sd.handle = sdHandle;
return 0;
}
static int memsSpiInit(void)
{
SPI_Params spiParams;
SPI_Handle memsSpiHandle;
// SPI_init();
SPI_Params_init(&spiParams);
spiParams.mode = SPI_MASTER;
spiParams.bitRate = 3000000;
spiParams.dataSize = 8;
spiParams.frameFormat = SPI_POL1_PHA1;
memsSpiHandle = SPI_open(Board_SPI1, &spiParams);
if( memsSpiHandle==NULL )
{
//SPI_open() failed, Error opening SPI
SPI_close(memsSpiHandle);
return -1;
//while (1);
}
return 0;
}
,这样写,还是会失败
SPI_Handle sdHandle;
SPI_Handle sdHandle0;
GPIO_init();
SPI_init();
sdHandle = SPI_open(Board_SPI0, NULL);
sdHandle0 = SPI_open(Board_SPI1, NULL);
if (sdHandle == NULL) {
Display_printf(display, 0, 0, "Error starting the SD card\n");
while (1);
}
if (sdHandle0 == NULL) {
Display_printf(display, 0, 0, "Error starting thespi\n");
while (1);
}
这样写, sdHandle0 = SPI_open(Board_SPI1, NULL);打开为NULL;还是打不开
CC1310_LAUNCHXL.h
#define CC1310_LAUNCHXL_SPI1_MISO IOID_5 /* RF1.20 */ //sensor
#define CC1310_LAUNCHXL_SPI1_MOSI IOID_6 /* RF1.18 */
#define CC1310_LAUNCHXL_SPI1_CLK IOID_10 /* RF1.16 */
#define CC1310_LAUNCHXL_SPI1_CSN IOID_4
#define CC1310_LAUNCHXL_SPI0_MISO IOID_14 //sd
#define CC1310_LAUNCHXL_SPI0_MOSI IOID_15
#define CC1310_LAUNCHXL_SPI0_CLK IOID_10
#define CC1310_LAUNCHXL_SPI0_CSN IOID_11
Board.h
#define Board_SPI0 CC1310_LAUNCHXL_SPI0
#define Board_SPI1 CC1310_LAUNCHXL_SPI1
分别是这样定义的
你SPI_open的第二個參數要處理,如下:
SPI_Handle masterSpi; SPI_Params spiParams; /* Open SPI as master (default) */ SPI_Params_init(&spiParams); spiParams.frameFormat = SPI_POL0_PHA1; spiParams.bitRate = 4000000; masterSpi = SPI_open(Board_SPI1, &spiParams);
SPI_Handle sdHandle;
SPI_Handle sdHandle0;
GPIO_init();
SPI_init();
SPI_Params spiParams;
SPI_Params spiParams0;
SPI_Params_init(&spiParams);
spiParams.mode = SPI_MASTER;
spiParams.bitRate = 3000000;
spiParams.dataSize = 8;
spiParams.frameFormat = SPI_POL1_PHA1;
SPI_Params_init(&spiParams0);
spiParams0.mode = SPI_MASTER;
spiParams0.bitRate = 3000000;
spiParams0.dataSize = 8;
spiParams0.frameFormat = SPI_POL0_PHA1;
sdHandle = SPI_open(Board_SPI0, &spiParams);
sdHandle0 = SPI_open(Board_SPI1, &spiParams0);
这样写,第二个还是不可以
我用下面的程序取代sdraw mainThread理的程序去測試SPI open,是沒問題的
SPI_Handle masterSpi0; SPI_Params spiParams0; SPI_Handle masterSpi; SPI_Params spiParams; SPI_init(); /* Open SPI as master (default) */ SPI_Params_init(&spiParams0); spiParams0.frameFormat = SPI_POL0_PHA1; 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"); } SPI_Params_init(&spiParams); spiParams.frameFormat = SPI_POL0_PHA1; spiParams.bitRate = 4000000; masterSpi = SPI_open(Board_SPI1, &spiParams); if (masterSpi == NULL) { Display_printf(display, 0, 0, "Error initializing master SPI\n"); while (1); } else { Display_printf(display, 0, 0, "Master SPI initialized\n"); }
GPIO_write(CC1310_LAUNCHXL_SPI0_CSN,1);
我还有一个问题,片选信号,这样写,可以实现拉高么?
目前ti應該沒有提供关掉DMA配置的spi driver,你為什麼需要關掉呢?
#define CC1310_LAUNCHXL_SPI1_MISO IOID_5 /* RF1.20 */ //sensor
#define CC1310_LAUNCHXL_SPI1_MOSI IOID_6 /* RF1.18 */
#define CC1310_LAUNCHXL_SPI1_CLK IOID_10 /* RF1.16 */
#define CC1310_LAUNCHXL_SPI1_CSN IOID_4
#define CC1310_LAUNCHXL_SPI0_MISO IOID_14 //sd
#define CC1310_LAUNCHXL_SPI0_MOSI IOID_15
#define CC1310_LAUNCHXL_SPI0_CLK IOID_10
#define CC1310_LAUNCHXL_SPI0_CSN IOID_11
使用两个spi,无法同时使用,关闭一个,另外一个才可以使用
我剛剛又試了一次是沒問題的啊,你可以把你的mainThread完整程序貼上來給我看看嗎?
void *mainThread(void *arg0)
{
SPI_Handle masterSpi0;
SPI_Params spiParams0;
SPI_Handle masterSpi;
SPI_Params spiParams;
SPI_init();
/* Open SPI as master (default) */
SPI_Params_init(&spiParams0);
spiParams0.frameFormat = SPI_POL0_PHA1;
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");
}
// SPI_close(masterSpi0);
//
// GPIO_write(CC1310_LAUNCHXL_SPI0_CSN,0);
// GPIO_write(CC1310_LAUNCHXL_SPI1_CSN,1);
SPI_Params_init(&spiParams);
spiParams.frameFormat = SPI_POL0_PHA1;
spiParams.bitRate = 4000000;
masterSpi = SPI_open(Board_SPI1, &spiParams);
if (masterSpi == NULL) {
Display_printf(display, 0, 0, "Error initializing master SPI\n");
while (1);
}
else {
Display_printf(display, 0, 0, "Master SPI initialized\n");
}
}
和您的一样的程序,只是在
#define CC1310_LAUNCHXL_SPI1_MISO IOID_5 /* RF1.20 */ //sensor
#define CC1310_LAUNCHXL_SPI1_MOSI IOID_6 /* RF1.18 */
#define CC1310_LAUNCHXL_SPI1_CLK IOID_10 /* RF1.16 */
#define CC1310_LAUNCHXL_SPI1_CSN IOID_4
#define CC1310_LAUNCHXL_SPI0_MISO IOID_14 //sd
#define CC1310_LAUNCHXL_SPI0_MOSI IOID_15
#define CC1310_LAUNCHXL_SPI0_CLK IOID_10
#define CC1310_LAUNCHXL_SPI0_CSN IOID_11
我把两个spi的引脚配置改成这样,其他的没做修改了
unsigned char SPIreceiveByte()
{
uint8_t n=8; //
uint8_t tdata;
uint8_t MISO;
GPIO_write(CC1310_LAUNCHXL_SPI1_CLK,1);
GPIO_write(CC1310_LAUNCHXL_SPI1_CSN,0);
while(n--)
{
CPUdelay(16);
GPIO_write(CC1310_LAUNCHXL_SPI1_CLK,0); //时钟为低电平时,
CPUdelay(16);
tdata = tdata<<1;
MISO = GPIO_read(CC1310_LAUNCHXL_SPI1_MISO);
if(MISO == 1)
tdata = tdata|0x01; //接收位为1,数据最后一位为1
else
tdata = tdata&0xfe;
GPIO_write(CC1310_LAUNCHXL_SPI1_CLK,1);
}
GPIO_write(CC1310_LAUNCHXL_SPI1_CSN,1);
return(tdata);
}
您好,io口可以这样模拟spi通讯么
我用下面的腳位配置是可以的,你要不要試試
#define CC1310_LAUNCHXL_SPI0_MISO IOID_5 /* RF1.20 */ #define CC1310_LAUNCHXL_SPI0_MOSI IOID_6 /* RF1.18 */ #define CC1310_LAUNCHXL_SPI0_CLK IOID_10 /* RF1.16 */ #define CC1310_LAUNCHXL_SPI0_CSN IOID_4 #define CC1310_LAUNCHXL_SPI1_MISO IOID_2 #define CC1310_LAUNCHXL_SPI1_MOSI IOID_3 #define CC1310_LAUNCHXL_SPI1_CLK IOID_19 #define CC1310_LAUNCHXL_SPI1_CSN IOID_18 /* UART Board */ #define CC1310_LAUNCHXL_UART_RX PIN_UNASSIGNED /* RXD */ #define CC1310_LAUNCHXL_UART_TX PIN_UNASSIGNED /* TXD */ #define CC1310_LAUNCHXL_UART_CTS PIN_UNASSIGNED /* CTS */ #define CC1310_LAUNCHXL_UART_RTS PIN_UNASSIGNED /* RTS */
你的CC1310_LAUNCHXL_SPI1_CLK和CC1310_LAUNCHXL_SPI0_CLK要用不同腳位啊,不能共用IOID_10
如果要共用CLK,那基本上應該是連MOSI/MISO都要共用,只有不同的spi slave的CS接到不同腳位