我對c語言非常陌生(obj-c,通常很快),我正在使用一些賽普拉斯BLE板。我試圖控制一個簡單的LED。基於數據表在C中創建數組
每the documentation我應該簡單地寫一個SPI總線來控制LED。
所以我寫0的32位開始。然後是RGB數組。然後是全部1的32位。以下是我目前想:
static uint8 startFrame[32] = {0,0,0,0};
static uint8 colorFrame[32] = {1, 255, 0, 0};
static uint8 endFrame[32] = {1,1,1,1};
SPI_1_SpiUartPutArray(startFrame, 32);
SPI_1_SpiUartPutArray(colorFrame, 32);
SPI_1_SpiUartPutArray(endFrame, 32);
我的想法是,一個int
爲8位所以把{1,1,1,1}
應該是大小32.同樣,我非常新的,通過這次黑客攻擊我的方式。很感謝任何形式的幫助!
的文檔SPI_1_SpiUartPutArray
:
/*******************************************************************************
* Function Name: SPI_1_SpiUartPutArray
****************************************************************************//**
*
* Places an array of data into the transmit buffer to be sent.
* This function is blocking and waits until there is a space available to put
* all the requested data in the transmit buffer. The array size can be greater
* than transmit buffer size.
*
* \param wrBuf: pointer to an array of data to be placed in transmit buffer.
* The width of the data to be transmitted depends on TX data width selection
* (the data bit counting starts from LSB for each array element).
* \param count: number of data elements to be placed in the transmit buffer.
*
* \globalvars
* SPI_1_txBufferHead - the start index to put data into the
* software transmit buffer.
* SPI_1_txBufferTail - start index to get data from the software
* transmit buffer.
*
*******************************************************************************/
void SPI_1_SpiUartPutArray(const uint8 wrBuf[], uint32 count)
{
uint32 i;
for (i=0u; i < count; i++)
{
SPI_1_SpiUartWriteTxData((uint32) wrBuf[i]);
}
}
這我也試過這樣:
static uint8 startFrame[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static uint8 colorFrame[32] = {1,1,1, 1,1,1,1,1 , 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
static uint8 endFrame[32] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
這:
static uint8 startFrame[4] = {0x00, 0x00, 0x00, 0x00};
static uint8 colorFrame[4] = {0xff, 0xff, 0xff, 0xff};
static uint8 endFrame[4] = {0xff, 0xff, 0xff ,0xff};
SPI_1_SpiUartPutArray(startFrame, 4);
SPI_1_SpiUartPutArray(colorFrame, 4);
SPI_1_SpiUartPutArray(endFrame, 4);
這:
static uint8 startFrame[4] = {0,0,0,0};
static uint8 colorFrame[4] = {255, <R>, <G>, <B>};
static uint8 endFrame[4] = {255,255,255,255};
SPI_1_SpiUartPutArray(startFrame, 4);
SPI_1_SpiUartPutArray(colorFrame, 4); // multiple of these for each LED
SPI_1_SpiUartPutArray(endFrame, 4);
如果上述任何設置都是正確的,那麼它肯定是我寫入SPI的問題。
你的'static uint8 endFrame [32] = {1,1,1,1};'既不是一個32位元的'1'位數組(只有前4個元素是1,其他元素是0),也不是4個元素的0xFF字節數組(32位)。你似乎只寫一個LED日期[原文如此]字段。請注意,它的「全局」位域可能不能是「11111b」,或者像素爲白色時,項目可能與結束幀標記混淆。 –
你爲什麼改變這個問題?從評論和答案中糾正是沒有用的。 StackOverflow不是一個運行更新服務。 –
如有必要,在問題中添加附錄。但是,現在閱讀這個問題的人如何理解答案和評論呢? –