牛卧堂MCU技术交流
标题:
NUC029SGE 芯片與帶有 PDMA SPI 的 ws2812 一起使用
[打印本页]
作者:
admin
时间:
2022-10-19 17:04
标题:
NUC029SGE 芯片與帶有 PDMA SPI 的 ws2812 一起使用
你好,我叫natee。我是泰國人。我在清邁工作。現在我正在學習使用 NUC029SGE 芯片與帶有 PDMA SPI 的 ws2812 一起使用
http://www.nuvoton-mcu.com/forum ... mp;highlight=ws2812
即使在修復錯誤之後它也不起作用,我嘗試了鏈接中的示例。
https://m.blog.naver.com/PostVie ... ;logNo=221544870211
使用 SPI FIFO Master 不再起作用。
我正在嘗試訂閱論壇尋求幫助。
http://www.nuvoton-mcu.com/forum
已經用郵箱註冊了
[url=mailto
itipong@narit.or.th]Pitipong@narit.or.th[/url]
我沒有收到系統的回應,而且確認不是機器人的身份使用了漢字,漢字,讓我無法使用。我真的需要管理員的幫助,我想使用 nuvoton 芯片,它工作正常,請管理員幫助我。我覺得新唐芯片在泰國市場有很大的前途,5-6年前,新唐芯片和ST或者NXP價格相差不大,但是現在價格差距很大。我想做新唐芯片,也想賣給泰國人用。
謝謝你
我試圖實現的代碼 spi fifo
/**************************************************************************//**
* @file main.c
* @version V3.0
* $Revision: 3 $
* $Date: 17/05/04 1:53p $
* @brief Configure SPI0 as Master mode and demonstrate how to communicate
* with an off-chip SPI Slave device with FIFO mode. This sample
* code needs to work with SPI_SlaveFifoMode sample code.
*
* @note
* Copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
*
******************************************************************************/
#include <stdio.h>
#include "NUC029xGE.h"
#define MAX_LED_COUNT 50
uint8_t leds[MAX_LED_COUNT][3] = {{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},};
uint8_t ledCount=0;
uint8_t ledTotalCount=0;
uint8_t colorCount=0;
const uint32_t colorLookup[] = {
0x924924, 0x924926, 0x924934, 0x924936, 0x9249A4, 0x9249A6, 0x9249B4, 0x9249B6, 0x924D24, 0x924D26, 0x924D34, 0x924D36, 0x924DA4, 0x924DA6, 0x924DB4, 0x924DB6,
0x926924, 0x926926, 0x926934, 0x926936, 0x9269A4, 0x9269A6, 0x9269B4, 0x9269B6, 0x926D24, 0x926D26, 0x926D34, 0x926D36, 0x926DA4, 0x926DA6, 0x926DB4, 0x926DB6,
0x934924, 0x934926, 0x934934, 0x934936, 0x9349A4, 0x9349A6, 0x9349B4, 0x9349B6, 0x934D24, 0x934D26, 0x934D34, 0x934D36, 0x934DA4, 0x934DA6, 0x934DB4, 0x934DB6,
0x936924, 0x936926, 0x936934, 0x936936, 0x9369A4, 0x9369A6, 0x9369B4, 0x9369B6, 0x936D24, 0x936D26, 0x936D34, 0x936D36, 0x936DA4, 0x936DA6, 0x936DB4, 0x936DB6,
0x9A4924, 0x9A4926, 0x9A4934, 0x9A4936, 0x9A49A4, 0x9A49A6, 0x9A49B4, 0x9A49B6, 0x9A4D24, 0x9A4D26, 0x9A4D34, 0x9A4D36, 0x9A4DA4, 0x9A4DA6, 0x9A4DB4, 0x9A4DB6,
0x9A6924, 0x9A6926, 0x9A6934, 0x9A6936, 0x9A69A4, 0x9A69A6, 0x9A69B4, 0x9A69B6, 0x9A6D24, 0x9A6D26, 0x9A6D34, 0x9A6D36, 0x9A6DA4, 0x9A6DA6, 0x9A6DB4, 0x9A6DB6,
0x9B4924, 0x9B4926, 0x9B4934, 0x9B4936, 0x9B49A4, 0x9B49A6, 0x9B49B4, 0x9B49B6, 0x9B4D24, 0x9B4D26, 0x9B4D34, 0x9B4D36, 0x9B4DA4, 0x9B4DA6, 0x9B4DB4, 0x9B4DB6,
0x9B6924, 0x9B6926, 0x9B6934, 0x9B6936, 0x9B69A4, 0x9B69A6, 0x9B69B4, 0x9B69B6, 0x9B6D24, 0x9B6D26, 0x9B6D34, 0x9B6D36, 0x9B6DA4, 0x9B6DA6, 0x9B6DB4, 0x9B6DB6,
0xD24924, 0xD24926, 0xD24934, 0xD24936, 0xD249A4, 0xD249A6, 0xD249B4, 0xD249B6, 0xD24D24, 0xD24D26, 0xD24D34, 0xD24D36, 0xD24DA4, 0xD24DA6, 0xD24DB4, 0xD24DB6,
0xD26924, 0xD26926, 0xD26934, 0xD26936, 0xD269A4, 0xD269A6, 0xD269B4, 0xD269B6, 0xD26D24, 0xD26D26, 0xD26D34, 0xD26D36, 0xD26DA4, 0xD26DA6, 0xD26DB4, 0xD26DB6,
0xD34924, 0xD34926, 0xD34934, 0xD34936, 0xD349A4, 0xD349A6, 0xD349B4, 0xD349B6, 0xD34D24, 0xD34D26, 0xD34D34, 0xD34D36, 0xD34DA4, 0xD34DA6, 0xD34DB4, 0xD34DB6,
0xD36924, 0xD36926, 0xD36934, 0xD36936, 0xD369A4, 0xD369A6, 0xD369B4, 0xD369B6, 0xD36D24, 0xD36D26, 0xD36D34, 0xD36D36, 0xD36DA4, 0xD36DA6, 0xD36DB4, 0xD36DB6,
0xDA4924, 0xDA4926, 0xDA4934, 0xDA4936, 0xDA49A4, 0xDA49A6, 0xDA49B4, 0xDA49B6, 0xDA4D24, 0xDA4D26, 0xDA4D34, 0xDA4D36, 0xDA4DA4, 0xDA4DA6, 0xDA4DB4, 0xDA4DB6,
0xDA6924, 0xDA6926, 0xDA6934, 0xDA6936, 0xDA69A4, 0xDA69A6, 0xDA69B4, 0xDA69B6, 0xDA6D24, 0xDA6D26, 0xDA6D34, 0xDA6D36, 0xDA6DA4, 0xDA6DA6, 0xDA6DB4, 0xDA6DB6,
0xDB4924, 0xDB4926, 0xDB4934, 0xDB4936, 0xDB49A4, 0xDB49A6, 0xDB49B4, 0xDB49B6, 0xDB4D24, 0xDB4D26, 0xDB4D34, 0xDB4D36, 0xDB4DA4, 0xDB4DA6, 0xDB4DB4, 0xDB4DB6,
0xDB6924, 0xDB6926, 0xDB6934, 0xDB6936, 0xDB69A4, 0xDB69A6, 0xDB69B4, 0xDB69B6, 0xDB6D24, 0xDB6D26, 0xDB6D34, 0xDB6D36, 0xDB6DA4, 0xDB6DA6, 0xDB6DB4, 0xDB6DB6,
};
void setTotalPixels(uint8_t total)
{
if(total >= MAX_LED_COUNT)
{
ledTotalCount = MAX_LED_COUNT;
}
else
{
ledTotalCount = total;
}
}
void setPixel(uint8_t id, uint8_t r, uint8_t g, uint8_t b)
{
if(id >= MAX_LED_COUNT){
return;}
leds[id][0] = r;
leds[id][1] = g;
leds[id][2] = b;
}
void getPixel(uint8_t id, uint8_t *r, uint8_t *g, uint8_t *b)
{
if(id >= MAX_LED_COUNT){
return;}
*r = leds[id][0];
*g = leds[id][1];
*b = leds[id][2];
}
void showLED()
{
ledCount=0;
colorCount=0;
SPI_EnableInt(SPI0, SPI_FIFOCTL_TXTHIEN_Msk);
}
/* Function prototype declaration */
void SYS_Init(void);
void SPI_Init(void);
/* ------------- */
/* Main function */
/* ------------- */
int main(void)
{
/* Unlock protected registers */
SYS_UnlockReg();
/* Init System, IP clock and multi-function I/O. */
SYS_Init();
/* Lock protected registers */
SYS_LockReg();
/* Configure UART0: 115200, 8-bit word, no parity bit, 1 stop bit. */
UART_Open(UART0, 115200);
SPI_Init();
printf("\n\n");
printf("+----------------------------------------------------------------------+\n");
setTotalPixels(8);
printf("\nt");
while(1){
setPixel(0,255,0,0);
showLED();
setPixel(1,255,0,0);
showLED();
setPixel(2,255,0,0);
showLED();
setPixel(3,255,0,0);
showLED();
}
}
void SYS_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock */
/*---------------------------------------------------------------------------------------------------------*/
/* Enable external 12MHz XTAL */
CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
/* Waiting for clock ready */
CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);
/* Switch HCLK clock source to HXT and set HCLK divider to 1 */
CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HXT, CLK_CLKDIV0_HCLK(1));
/* Select HXT as the clock source of UART0 */
CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UARTSEL_HXT, CLK_CLKDIV0_UART(1));
/* Select PCLK0 as the clock source of SPI0 */
CLK_SetModuleClock(SPI0_MODULE, CLK_CLKSEL2_SPI0SEL_PCLK0, MODULE_NoMsk);
/* Enable UART peripheral clock */
CLK_EnableModuleClock(UART0_MODULE);
/* Enable SPI0 peripheral clock */
CLK_EnableModuleClock(SPI0_MODULE);
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CyclesPerUs automatically. */
SystemCoreClockUpdate();
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set multi-function pins for UART0 RXD and TXD */
SYS->GPA_MFPL &= ~(SYS_GPA_MFPL_PA2MFP_Msk | SYS_GPA_MFPL_PA3MFP_Msk);
SYS->GPA_MFPL |= (SYS_GPA_MFPL_PA3MFP_UART0_RXD | SYS_GPA_MFPL_PA2MFP_UART0_TXD);
/* Setup SPI0 multi-function pins */
SYS->GPB_MFPL &= ~(SYS_GPB_MFPL_PB4MFP_Msk | SYS_GPB_MFPL_PB5MFP_Msk | SYS_GPB_MFPL_PB6MFP_Msk | SYS_GPB_MFPL_PB7MFP_Msk);
SYS->GPB_MFPL |= SYS_GPB_MFPL_PB4MFP_SPI0_SS | SYS_GPB_MFPL_PB5MFP_SPI0_MOSI | SYS_GPB_MFPL_PB6MFP_SPI0_MISO | SYS_GPB_MFPL_PB7MFP_SPI0_CLK;
}
void SPI_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init SPI */
/*---------------------------------------------------------------------------------------------------------*/
printf("\ns");
SPI_Open(SPI0, SPI_MASTER, SPI_MODE_0, 24, 2400000);
SPI_EnableAutoSS(SPI0, SPI_SS, SPI_SS_ACTIVE_HIGH);
SPI_SetFIFO(SPI0, 3, 2);
NVIC_EnableIRQ(SPI0_IRQn);
}
void SPI0_IRQHandler(void)
{
/* Check TX FULL flag and TX data count */
printf("\np");
if((SPI_GET_TX_FIFO_FULL_FLAG(SPI0) == 0) && (ledCount < ledTotalCount))
{
/* Write to TX FIFO */
SPI_WRITE_TX(SPI0, colorLookup[leds[ledCount][colorCount++]]);
printf("\nx");
if(colorCount >= 3)
{
//ledCount ??
ledCount++;
//led ?? ??? ? ???
colorCount=0;
}
}else{
ledCount=0;
colorCount=0;
SPI_DisableInt(SPI0, SPI_FIFOCTL_TXTHIEN_Msk); /* Disable TX FIFO threshold interrupt */
}
}
复制代码
作者:
admin
时间:
2022-10-19 17:15
@natee.th
作者:
admin
时间:
2022-10-20 10:39
程序没有发出SPI数据是因为SPI TX FIFO阈值中断使能写错了。
enable和disable如下:SPI_EnableInt(SPI0, SPI_FIFO_TXTH_INT_MASK); SPI_DisableInt(SPI0, SPI_FIFO_TXTH_INT_MASK);
SPI_MasterFifoMode例程也无输出是同样的问题,您去官网上下载最新版本的BSP即可。
https://www.nuvoton.com.cn/produ ... roup=Software&tab=2
作者:
admin
时间:
2022-10-21 10:54
現在可以用了謝謝
#include <stdio.h>
#include "NUC029xGE.h"
#include <math.h>
#define PI 3.14159265
#define MAX_LED_COUNT 50
uint8_t leds[MAX_LED_COUNT][3] = {{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00}};
uint8_t ledsB[MAX_LED_COUNT][3] = {{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},
{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00},{0x00, 0x00, 0x00}};
uint8_t ledCount=0;
uint8_t ledTotalCount=0;
uint8_t colorCount=0;
uint8_t Darkness=200;
uint8_t i= 0;
const uint32_t colorLookup[] = {
0x924924, 0x924926, 0x924934, 0x924936, 0x9249A4, 0x9249A6, 0x9249B4, 0x9249B6, 0x924D24, 0x924D26, 0x924D34, 0x924D36, 0x924DA4, 0x924DA6, 0x924DB4, 0x924DB6,
0x926924, 0x926926, 0x926934, 0x926936, 0x9269A4, 0x9269A6, 0x9269B4, 0x9269B6, 0x926D24, 0x926D26, 0x926D34, 0x926D36, 0x926DA4, 0x926DA6, 0x926DB4, 0x926DB6,
0x934924, 0x934926, 0x934934, 0x934936, 0x9349A4, 0x9349A6, 0x9349B4, 0x9349B6, 0x934D24, 0x934D26, 0x934D34, 0x934D36, 0x934DA4, 0x934DA6, 0x934DB4, 0x934DB6,
0x936924, 0x936926, 0x936934, 0x936936, 0x9369A4, 0x9369A6, 0x9369B4, 0x9369B6, 0x936D24, 0x936D26, 0x936D34, 0x936D36, 0x936DA4, 0x936DA6, 0x936DB4, 0x936DB6,
0x9A4924, 0x9A4926, 0x9A4934, 0x9A4936, 0x9A49A4, 0x9A49A6, 0x9A49B4, 0x9A49B6, 0x9A4D24, 0x9A4D26, 0x9A4D34, 0x9A4D36, 0x9A4DA4, 0x9A4DA6, 0x9A4DB4, 0x9A4DB6,
0x9A6924, 0x9A6926, 0x9A6934, 0x9A6936, 0x9A69A4, 0x9A69A6, 0x9A69B4, 0x9A69B6, 0x9A6D24, 0x9A6D26, 0x9A6D34, 0x9A6D36, 0x9A6DA4, 0x9A6DA6, 0x9A6DB4, 0x9A6DB6,
0x9B4924, 0x9B4926, 0x9B4934, 0x9B4936, 0x9B49A4, 0x9B49A6, 0x9B49B4, 0x9B49B6, 0x9B4D24, 0x9B4D26, 0x9B4D34, 0x9B4D36, 0x9B4DA4, 0x9B4DA6, 0x9B4DB4, 0x9B4DB6,
0x9B6924, 0x9B6926, 0x9B6934, 0x9B6936, 0x9B69A4, 0x9B69A6, 0x9B69B4, 0x9B69B6, 0x9B6D24, 0x9B6D26, 0x9B6D34, 0x9B6D36, 0x9B6DA4, 0x9B6DA6, 0x9B6DB4, 0x9B6DB6,
0xD24924, 0xD24926, 0xD24934, 0xD24936, 0xD249A4, 0xD249A6, 0xD249B4, 0xD249B6, 0xD24D24, 0xD24D26, 0xD24D34, 0xD24D36, 0xD24DA4, 0xD24DA6, 0xD24DB4, 0xD24DB6,
0xD26924, 0xD26926, 0xD26934, 0xD26936, 0xD269A4, 0xD269A6, 0xD269B4, 0xD269B6, 0xD26D24, 0xD26D26, 0xD26D34, 0xD26D36, 0xD26DA4, 0xD26DA6, 0xD26DB4, 0xD26DB6,
0xD34924, 0xD34926, 0xD34934, 0xD34936, 0xD349A4, 0xD349A6, 0xD349B4, 0xD349B6, 0xD34D24, 0xD34D26, 0xD34D34, 0xD34D36, 0xD34DA4, 0xD34DA6, 0xD34DB4, 0xD34DB6,
0xD36924, 0xD36926, 0xD36934, 0xD36936, 0xD369A4, 0xD369A6, 0xD369B4, 0xD369B6, 0xD36D24, 0xD36D26, 0xD36D34, 0xD36D36, 0xD36DA4, 0xD36DA6, 0xD36DB4, 0xD36DB6,
0xDA4924, 0xDA4926, 0xDA4934, 0xDA4936, 0xDA49A4, 0xDA49A6, 0xDA49B4, 0xDA49B6, 0xDA4D24, 0xDA4D26, 0xDA4D34, 0xDA4D36, 0xDA4DA4, 0xDA4DA6, 0xDA4DB4, 0xDA4DB6,
0xDA6924, 0xDA6926, 0xDA6934, 0xDA6936, 0xDA69A4, 0xDA69A6, 0xDA69B4, 0xDA69B6, 0xDA6D24, 0xDA6D26, 0xDA6D34, 0xDA6D36, 0xDA6DA4, 0xDA6DA6, 0xDA6DB4, 0xDA6DB6,
0xDB4924, 0xDB4926, 0xDB4934, 0xDB4936, 0xDB49A4, 0xDB49A6, 0xDB49B4, 0xDB49B6, 0xDB4D24, 0xDB4D26, 0xDB4D34, 0xDB4D36, 0xDB4DA4, 0xDB4DA6, 0xDB4DB4, 0xDB4DB6,
0xDB6924, 0xDB6926, 0xDB6934, 0xDB6936, 0xDB69A4, 0xDB69A6, 0xDB69B4, 0xDB69B6, 0xDB6D24, 0xDB6D26, 0xDB6D34, 0xDB6D36, 0xDB6DA4, 0xDB6DA6, 0xDB6DB4, 0xDB6DB6,
};
void setTotalPixels(uint8_t total)
{
if(total >= MAX_LED_COUNT)
{
ledTotalCount = MAX_LED_COUNT;
}
else
{
ledTotalCount = total;
}
}
void setPixel(uint8_t id, uint8_t r, uint8_t g, uint8_t b)
{
if(id >= MAX_LED_COUNT){return;}
leds[id][0] = g;
leds[id][1] = r;
leds[id][2] = b;
}
void update_Brightness(){
for(i=0; i<ledTotalCount; i++){
ledsB[0] = leds[0];
ledsB[1] = leds[1];
ledsB[2] = leds[2];
uint16_t i = 0;
uint16_t j = 0;
/* next step
if (brightness > 45) brightness = 45;
for (i=0; i<MAX_LED; i++)
{
LED_Mod[0] = LED_Data[0];
for (j=1; j<4; j++)
{
float angle = 90-brightness; // in degrees
angle = angle*PI / 180; // in rad
LED_Mod[j] = (LED_Data[j])/(tan(angle));
}
}*/
}
}
void getPixel(uint8_t id, uint8_t *r, uint8_t *g, uint8_t *b)
{
if(id >= MAX_LED_COUNT){return;}
*r = leds[id][0];
*g = leds[id][1];
*b = leds[id][2];
}
void showLED()
{
ledCount=0;
colorCount=0;
SPI_EnableInt(SPI0, SPI_FIFO_TXTH_INT_MASK);
}
/* Function prototype declaration */
void SYS_Init(void);
void SPI_Init(void);
/* ------------- */
/* Main function */
/* ------------- */
int main(void)
{
/* Unlock protected registers */
SYS_UnlockReg();
/* Init System, IP clock and multi-function I/O. */
SYS_Init();
/* Lock protected registers */
SYS_LockReg();
/* Configure UART0: 115200, 8-bit word, no parity bit, 1 stop bit. */
UART_Open(UART0, 115200);
SPI_Init();
printf("\n\n");
printf("setTotalPixels\n");
setTotalPixels(5);
setPixel(0,255,0,0);
setPixel(1,0,255,0);
setPixel(2,0,0,255);
setPixel(3,0,255,0);
setPixel(4,255,0,0);
//showLED();
while(1){
printf("\n\nPress any key to start sending.\n");
getchar();
update_Brightness();
showLED();
printf("\n End.\n");
}
}
void SYS_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock */
/*---------------------------------------------------------------------------------------------------------*/
/* Enable external 12MHz XTAL */
CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
/* Waiting for clock ready */
CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);
/* Switch HCLK clock source to HXT and set HCLK divider to 1 */
CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HXT, CLK_CLKDIV0_HCLK(1));
/* Select HXT as the clock source of UART0 */
CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UARTSEL_HXT, CLK_CLKDIV0_UART(1));
/* Select PCLK0 as the clock source of SPI0 */
CLK_SetModuleClock(SPI0_MODULE, CLK_CLKSEL2_SPI0SEL_PCLK0, MODULE_NoMsk);
/* Enable UART peripheral clock */
CLK_EnableModuleClock(UART0_MODULE);
/* Enable SPI0 peripheral clock */
CLK_EnableModuleClock(SPI0_MODULE);
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CyclesPerUs automatically. */
SystemCoreClockUpdate();
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set multi-function pins for UART0 RXD and TXD */
SYS->GPA_MFPL &= ~(SYS_GPA_MFPL_PA2MFP_Msk | SYS_GPA_MFPL_PA3MFP_Msk);
SYS->GPA_MFPL |= (SYS_GPA_MFPL_PA3MFP_UART0_RXD | SYS_GPA_MFPL_PA2MFP_UART0_TXD);
/* Setup SPI0 multi-function pins */
SYS->GPB_MFPL &= ~(SYS_GPB_MFPL_PB4MFP_Msk | SYS_GPB_MFPL_PB5MFP_Msk | SYS_GPB_MFPL_PB6MFP_Msk | SYS_GPB_MFPL_PB7MFP_Msk);
SYS->GPB_MFPL |= SYS_GPB_MFPL_PB4MFP_SPI0_SS | SYS_GPB_MFPL_PB5MFP_SPI0_MOSI | SYS_GPB_MFPL_PB6MFP_SPI0_MISO | SYS_GPB_MFPL_PB7MFP_SPI0_CLK;
}
void SPI_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init SPI */
/*---------------------------------------------------------------------------------------------------------*/
SPI_Open(SPI0, SPI_MASTER, SPI_MODE_0, 24 , 2400000);
SPI_EnableAutoSS(SPI0, SPI_SS, SPI_SS_ACTIVE_HIGH);
NVIC_EnableIRQ(SPI0_IRQn);
}
void SPI0_IRQHandler(void)
{
/* Check TX FULL flag and TX data count */
if((SPI_GET_TX_FIFO_FULL_FLAG(SPI0) == 0) && (ledCount < ledTotalCount))
{
/* Write to TX FIFO */
SPI_WRITE_TX(SPI0, colorLookup[ledsB[ledCount][colorCount++]]);
if(colorCount >= 3){
ledCount++;
colorCount=0;
}
}else{
ledCount=0;
colorCount=0;
SPI_DisableInt(SPI0, SPI_FIFO_TXTH_INT_MASK); /* Disable TX FIFO threshold interrupt */
}
}
复制代码
欢迎光临 牛卧堂MCU技术交流 (http://nuvoton-mcu.com/)
Powered by Discuz! X3.2