STM32F429发现SPI寄存器

时间:2014-08-21 13:46:42

标签: cpu-registers spi stm32f4discovery

我正在尝试使用 STM32F429发现板,以便通过SPI以仅发送模式与LCD通信。但是,每次写入数据寄存器进行输出时,我都会在调试视图中看不到任何内容( CrossStudio )。

int main(void) {
int j;

    SET_BIT(RCC->AHB1ENR,(RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIOAEN) );


    MODIFY_REG(GPIOC->MODER,
               (GPIO_MODER_MODER10 | GPIO_MODER_MODER12)  , 
               (GPIO_MODER_MODER10_1 | GPIO_MODER_MODER12_1) ); // Sets to alternate function

    SET_BIT(GPIOC->OTYPER, (GPIO_OTYPER_OT_10 | GPIO_OTYPER_OT_12)); // Set output to push-pull type
    CLEAR_BIT(GPIOC->PUPDR, (GPIO_PUPDR_PUPDR10 | GPIO_PUPDR_PUPDR12) ); // Disable push pull resistors
SET_BIT(GPIOC->OSPEEDR, (GPIO_OSPEEDER_OSPEEDR10 | GPIO_OSPEEDER_OSPEEDR12) ); // Set speed high
     /* Set the Alternate Function for the SPI3 pins */
   // Port C Pins 7-0
    GPIOC->AFR[0] = 0x00000000; // PTC lower order pins are default
    // Port C Pins 15-8
    GPIOC->AFR[1] = 0x00066600; // PTC pins 10, 11, and 12 are for SPI (AF6 = 0x6)

    // Set up SS for screen
    MODIFY_REG(GPIOA->MODER, GPIO_MODER_MODER4 , GPIO_MODER_MODER4_0 );

    SET_BIT(GPIOA->BSRRL, 0b10000); //Sets pin 4 high





   // Enable the peripheral clock for SPI3
    SET_BIT(RCC->APB1ENR, RCC_APB1ENR_SPI3EN);
    CLEAR_BIT(SPI3->CR1, SPI_CR1_CPHA);
    CLEAR_BIT(SPI3->CR1, SPI_CR1_CPOL);
    //SET_BIT(SPI3->CR1, SPI_CR1_BIDIMODE);
    //SET_BIT(SPI3->CR1, SPI_CR1_BIDIOE); 
    SET_BIT(SPI3->CR1, SPI_CR1_SSM);//
    SET_BIT(SPI3->CR1, SPI_CR1_SSI);
    SET_BIT(SPI3->CR1, SPI_CR1_MSTR); // Set Master configuration
    /* TODO: Set Baud to 2 MHz (not just a random prescaler) */
    MODIFY_REG(SPI3->CR1, SPI_CR1_BR, SPI_CR1_BR); //Set to fCLK/256
    CLEAR_BIT(SPI3->CR1, SPI_CR1_LSBFIRST); // write out MSB first
    SET_BIT(SPI3->CR1, SPI_CR1_SPE); // Enable SPI3

transmitData[0]= MODE_CLEAR;
transmitData[1]=0x00;


    for(j = 0; j < 2; j++) {
        //TM_SPI_Send(SPI3, transmitData[j]);
                      SPI3->DR = transmitData[j]; // Write data to the data register
                    while( !(READ_BIT(SPI3->SR, SPI_SR_TXE)) ); // Wait until transmit is complete
                    while( READ_BIT(SPI3->SR, SPI_SR_BSY) );
    }
            SET_BIT(GPIOA->BSRRH, 0b10000); //Sets pin 4 low

引脚4是我的芯片选择引脚,我的示波器显示工作正常。我只是无法从SPI引脚中获取任何信息。

1 个答案:

答案 0 :(得分:0)

原来我输出意外设置为开漏,当我需要CLEAR_BIT时使用了SET_BIT

       CLEAR_BIT(GPIOC->OTYPER, (GPIO_OTYPER_OT_10 | GPIO_OTYPER_OT_12)); // Set output to push-pull type