This commit is contained in:
Markus Koch 2021-03-21 11:38:31 +01:00
parent 08a2581297
commit 44c9186c03
3 changed files with 65 additions and 0 deletions

View File

@ -166,6 +166,45 @@ void ConfigureUART()
NVIC_Init(&NVIC_InitStruct);*/ NVIC_Init(&NVIC_InitStruct);*/
} }
void ConfigureDMX()
{
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruct;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
// Set up UART GPIOs
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
// Set up control GPIOs
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
// Set up UART
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
USART_InitStruct.USART_BaudRate = 250000;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_StopBits = USART_StopBits_2;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_Init(USART2, &USART_InitStruct);
USART_Cmd(USART2, ENABLE);
}
void ConfigureLED() void ConfigureLED()
{ {
ConfigureGPIO(LED_RED, INOUT_OUT); ConfigureGPIO(LED_RED, INOUT_OUT);

View File

@ -57,7 +57,13 @@ void ConfigureGPIO( gpio gpio, int parameters );
#define LED_BLUE (LEDPIN+1) #define LED_BLUE (LEDPIN+1)
#define LED_RED (LEDPIN+2) #define LED_RED (LEDPIN+2)
#define DMX_TX_EN GPIOOn(1)
#define DMX_TX_DIS GPIOOff(1)
#define DMX_RX_EN GPIOOff(0)
#define DMX_RX_DIS GPIOOn(0)
void ConfigureUART(); void ConfigureUART();
void ConfigureDMX();
void ConfigureLED(); void ConfigureLED();
void JumpToBootloader(void); void JumpToBootloader(void);

View File

@ -111,6 +111,24 @@ void EXTI0_IRQHandler(void)
} }
} }
void test()
{
int i;
char str[] = "AAAATest\r\n";
char *buf;
DMX_TX_EN;
while (1) {
buf = str;
for (i=strlen(buf); i > 0; --i) {
while (!(USART2->SR & USART_SR_TXE));
USART2->DR = (uint16_t)(*((char*) buf) & 0x01FF);
buf++;
}
}
}
int main(void) int main(void)
{ {
uint32_t i = 0; uint32_t i = 0;
@ -125,6 +143,7 @@ int main(void)
float fv = RCC_Clocks.HCLK_Frequency / 1000000.0f; float fv = RCC_Clocks.HCLK_Frequency / 1000000.0f;
ConfigureUART(); ConfigureUART();
ConfigureDMX();
InitColorChord(); InitColorChord();
Configure_PA0(); Configure_PA0();
InitSPI2812(); InitSPI2812();
@ -138,6 +157,7 @@ int main(void)
int c = 1; int c = 1;
LED_ON(LED_RED); LED_ON(LED_RED);
test();
while (1) { while (1) {
for (int a=0; a < NUM_LIN_LEDS; a++) { for (int a=0; a < NUM_LIN_LEDS; a++) {
ledOut[a*3 + 0] = c/2; ledOut[a*3 + 0] = c/2;