Hallo :) ich versuche gerade mit meinem STM32F100RB mit Hilfe des SPI-Interfaces das Shift-Register 74HC959 anzusteuern. Bekomme jedoch nicht das gewünschte Verhalten hin. Manchmal sind alle LEDs an und manchmal sind alle LEDs einfach aus, obwohl ich laut Programmcode ja die Ausgänge entsprechend schalten müsste. Könnt ihr mir vielleicht dabei helfen?
1 | void SPI_MyInit() { |
2 | SPI_I2S_DeInit(SPI1); |
3 | |
4 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_SPI1, ENABLE); |
5 | |
6 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; |
7 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
8 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; |
9 | GPIO_Init(GPIOA, &GPIO_InitStructure); |
10 | |
11 | SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; |
12 | SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; |
13 | SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; |
14 | SPI_InitStructure.SPI_CRCPolynomial = 0; |
15 | SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; |
16 | SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx; |
17 | SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB; |
18 | SPI_InitStructure.SPI_Mode = SPI_Mode_Master; |
19 | SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; |
20 | |
21 | SPI_Init(SPI1, &SPI_InitStructure); |
22 | SPI_CalculateCRC(SPI1, ENABLE); |
23 | SPI_Cmd(SPI1, ENABLE); |
24 | } |
1 | // main |
2 | |
3 | SPI_MyInit(); |
4 | |
5 | while(1) |
6 | { |
7 | SPI_I2S_SendData(SPI1, 0xFFFF); |
8 | Delay(0x1AFFFF); |
9 | |
10 | SPI_I2S_SendData(SPI1, 0x0000); |
11 | Delay(0x1AFFFF); |
12 | } |
Vielen Dank schonmal :)