[ST_MICRO]/STM32F42014. 12. 15. 18:17

STM32F4 UART interrupt 테스트

STM32F4 UART interrupt 테스트



void U0_SetInt(void)

{

    /* NVIC for USART1 */

    HAL_NVIC_SetPriority(USART1_IRQn, 0, 1);

    HAL_NVIC_EnableIRQ(USART1_IRQn);

    

      /* Enable the UART Data Register not empty Interrupt */

    __HAL_UART_ENABLE_IT(&UartHandle, UART_IT_RXNE);

}




void USART1_IRQHandler(void)

{

    U0_PutByte(U0_GetByte());

}


Posted by nexp

댓글을 달아 주세요

[ST_MICRO]/STM32F42014. 6. 17. 00:16

STM32F4 타이머 인터럽트 테스트 - 1초 만들기


STM32F4 타이머 인터럽트 테스트



STM32F4에서 TIM2, TIM5는 32bit 타이머 모드를 지원한다. 이를 이용하여 1초 만들기 테스트를 해 보았다.




STM32F4 타이머 인터럽트 초기화 함수

void TimerInit2(void)

{

    TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

    TIM_OCInitTypeDef  TIM_OCInitStructure;


    uint16_t PrescalerValue = 0;


    NVIC_InitTypeDef NVIC_InitStructure;


    /* TIM2 clock enable */

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);


    /* TIM2 gloabal Interrupt 초기화 */

    NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);


    //--------------------------------------------------------------------------

    /* Compute the prescaler value */

    PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 6000000) - 1; 


    /* Time base configuration */

    TIM_TimeBaseStructure.TIM_Period = (6000-1);   //Autoreload value (ARR) -> 1ms

    TIM_TimeBaseStructure.TIM_Prescaler = (6000-1);

    TIM_TimeBaseStructure.TIM_ClockDivision = 0;

    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;


    TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);


    /* Prescaler configuration */

    TIM_PrescalerConfig(TIM2, PrescalerValue, TIM_PSCReloadMode_Immediate);



    /* TIM Interrupts enable */

    TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);


    /* TIM2 enable counter */

    TIM_Cmd(TIM2, ENABLE);

    //--------------------------------------------------------------------------    

}




STM32F4 타이머 인터럽트 핸들러

void TIM2_IRQHandler(void)

{

if(TIM_GetITStatus(TIM2, TIM_IT_Update) == SET)

{

TIM_ClearITPendingBit(TIM2, TIM_IT_Update);

        Led2Toggle();

}  

}




Posted by nexp

댓글을 달아 주세요

[ST_MICRO]/STM32F42014. 1. 5. 15:56

STM32F429I-DISCO - STM32F4, DISCOVERY, EVAL BOARD


STM32F429I-DISCO - STM32F4, DISCOVERY, EVAL BOARD


http://kr.element14.com/stmicroelectronics/stm32f429i-disco/stm32f4-discovery-eval-board/dp/2355377?in_merch=New%20Products

Posted by nexp

댓글을 달아 주세요

[ST_MICRO]/STM32F42013. 4. 27. 21:30

STM32F4 - VS1053 MP3 Module Test

 STM32F4 - VS1053 MP3 Module Test

 

 

 

STM32F4 를 이용하여 MP3출력시 소비 전류 측정을 위해 [LCD-EXP EVM] 보드를 이용하여 테스트 했다.

 

SPI클럭을 1.2mhz로 구동하고 클럭 분주를 1/2 로 설정하니 전류가 80mA -> 65mA로 줄어 들었다.


클럭을 좀더 낮추니 (1/4) 60mA로 줄어 든다. 이 상태에서도 MP3출력은 잘된다.
이때 SPI클럭을 좀더 올려 줬다.
SPI1_InitStructure.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_8;

static void SetSysClock(void)
{
 :

    /* HCLK = SYSCLK / 1*/
//    RCC->CFGR |= RCC_CFGR_HPRE_DIV1;
    RCC->CFGR |= RCC_CFGR_HPRE_DIV4; 

:

}

 


사용하지 않는 페리 끌수 있으면 좀더 줄지 않을까...

저전력 MCU가 아니라서 옵션이 많지 않은것이 아쉽다.

 

[LCD-EXP EVM] 회로도


 

 

[STM32F4 EVM] VS1053 제어 드라이버 코드

 

//-----------------------------------------------------------------------------
// SD Card HAL
#define _DEBUG_FAT_FILE                 0


#define MMC_CS_PORT      GPIOA
#define MMC_CS_BIT      BIT7

#define MMC_CS_INIT()     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);\
          GPIO_InitStructure.GPIO_Pin = MMC_CS_BIT|BIT4|BIT5;\
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;\
          GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;\
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;\
          GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;\
          GPIO_Init(GPIOA, &GPIO_InitStructure);Sbi(PORTA, BIT4|BIT5)
         
#define MMC_CS_HIGH()     sbi(MMC_CS_PORT, MMC_CS_BIT)
#define MMC_CS_LOW()     cbi(MMC_CS_PORT, MMC_CS_BIT)
#define MMC_ASSERT_INIT()    MMC_CS_INIT();MMC_CS_HIGH()
#define MMC_ASSERT()     MMC_CS_LOW()
#define MMC_DEASSERT()     MMC_CS_HIGH()


#define MMC_SpiInit()     SPI1_Init()
#define MMC_SendByte     SPI1_WriteReadByte
#define MMC_Send(Data)      SPI1_WriteByte(Data)
#define MMC_Recv()      SPI1_WriteReadByte(0xFF)
#define MMC_RecvP(Data)     MMC_Send(0xFF); (*(Data)=SPI1_ReadByte())
#define MMC_SPISpeed     SPI1_SetSpeed

#define SPI_Mode3()

#define FAT_MAX_NUM_FILE          50

#define FCLK_SLOW()             MMC_SPISpeed(SPI_SPEED_1MHZ) 
#define FCLK_FAST()             MMC_SPISpeed(SPI_SPEED_MAX)
//-----------------------------------------------------------------------------

 


//-----------------------------------------------------------------------------
// VS1053 Drvier
//-----------------------------------------------------------------------------
#define VS_DREQ_BIT          BIT6
#define VS_DREQ_PORT         PORTA

#define VS_CS_BIT          BIT5
#define VS_CS_PORT          PORTA


#define VS_RST_BIT      
#define VS_RST_DDR      
#define VS_RST_PORT      


#define VS1003_DREQ()           ((GPIOA->IDR&VS_DREQ_BIT))


#define VS1003_CS_H()      Sbi(VS_CS_PORT, VS_CS_BIT)
#define VS1003_CS_L()      Cbi(VS_CS_PORT, VS_CS_BIT)

#define vs1003_enable()      VS1003_CS_L()
#define vs1003_disable()     VS1003_CS_H()

#define VS_XDCS_BIT          BIT4
#define VS_XDCS_PORT         GPIOA
#define VS1003_XDCS_H()      sbi(VS_XDCS_PORT, VS_XDCS_BIT)
#define VS1003_XDCS_L()      cbi(VS_XDCS_PORT, VS_XDCS_BIT)


#define VS1003_RESET_H()     //Sbi(VS_RST_PORT, VS_RST_BIT)
#define VS1003_RESET_L()     //Cbi(VS_RST_PORT, VS_RST_BIT)

#define IsVs1003DataReady()     (GPIOA->IDR&VS_DREQ_BIT)

#define VS_SendByte       SPI1_WriteReadByte
#define VS_InitSpi()      //SPI1_Init()
#define VS_SpiSpeed_Low()        SPI1_SetSpeed(SPI_SPEED_1MHZ)
#define VS_SpiSpeed_High()     SPI1_SetSpeed(SPI_SPEED_4MHZ)


#define MP3_PORT_INIT()         RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);\
              GPIO_InitStructure.GPIO_Pin = BIT4|BIT5;\
              GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;\
              GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;\
              GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;\
              GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;\
              GPIO_Init(GPIOA, &GPIO_InitStructure);\
              GPIO_InitStructure.GPIO_Pin = VS_DREQ_BIT;\
                                            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;\
              GPIO_Init(GPIOA, &GPIO_InitStructure);\
                                            VS1003_CS_H();VS1003_XDCS_H()
//-----------------------------------------------------------------------------

Posted by nexp

댓글을 달아 주세요

[ST_MICRO]/STM32F42012. 9. 10. 00:23

[STM32F4] I2C 테스트 - 3축 가속도 센서 TFT LCD 출력

[STM32F4] I2C 테스트 - 3축 가속도 센서 TFT LCD 출력

 

 

3축 가속도 센서를 테스트 해야할 일이 있어 STM32F407 보드를 이용하여 I2C 테스트를 해보았다. 기존 STM32F103 I2C 테스트 코드과 크게 차이 없이 테스트 가능했다.

 

[EXP-NET EVM] 보드에는 I2C(SPI)로 연결되는 자이로, 가속도, 온도, 압력 센서등의 모듈을 연결할 수 있는 표준핀맵 커넥터가 있다.

 

 

 

 

SM-Type EVM 에는 핀 8번에, M-Type EVM에는 핀 13번에 각각 CS핀이 할당되어 있다.

 

 

 

STM32F4 I2C테스트 동영상

STM32F407 을 이요하여 3가속도 센서의 데이터를 TFT-LCD에 그래프로 표시하는 테스트 예제




STM32F4 I2C 초기화 코드

void i2c_init1(unsigned int Speed)
{
 I2C_InitTypeDef  I2C_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);     
    //Configure I2C2 pins: SCL and SDA
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6| GPIO_Pin_7;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;    
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;    
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    //Connect pins to I2C peripheral
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1);  
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_I2C1);

    //I2C2 and I2C2 Periph clock enable
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

    I2C_DeInit(I2C1);    
 
    //I2C2 configuration
    I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
    I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
    I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
    I2C_InitStructure.I2C_OwnAddress1 = 0x33;
    I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
    I2C_InitStructure.I2C_ClockSpeed = Speed;
    I2C_Cmd(I2C1, ENABLE);
    I2C_Init(I2C1, &I2C_InitStructure);
}

 

 

STM32F4 가속도 센서 I2C 제어 코드 

//-----------------------------------------------------------------------------

// myAccel3LV02 HAL

#define MY_ACCEL3LV02_SPI_MODE 0

#define MY_ACCEL3LV02_I2C_MODE 1


//#define ACCEL_CS_BIT BIT6

//#define ACCEL_CS_PORT PORTB


#define ACCEL_CS_BIT BIT11

#define ACCEL_CS_PORT PORTE


#define ACCEL_CS_INIT() RCC_APB2PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);\

GPIO_InitStructure.GPIO_Pin=ACCEL_CS_BIT;\

GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;\

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;\

GPIO_Init(GPIOC, &GPIO_InitStructure);\

ACCEL_CS_DEASSERT()

#define ACCEL_CS_ASSERT() Cbi(ACCEL_CS_PORT, ACCEL_CS_BIT)

#define ACCEL_CS_DEASSERT() Sbi(ACCEL_CS_PORT, ACCEL_CS_BIT)


#define ACCEL_SPI_INIT() SPI0_Init()

#define ACCEL_Read SPI0_WriteReadByte

#define ACCEL_Write SPI0_WriteReadByte



#define myAccelI2C_INIT                 i2c2_init

#define myAccelI2C_START                i2c2_start

#define myAccelI2C_WRITE                i2c2_write

#define myAccelI2C_READ_NAK             i2c2_readNak

#define myAccelI2C_STOP                 i2c2_stop



//-----------------------------------------------------------------------------
//myAccel3LV02의 특정 레지스터에서 데이터를 읽어옴
unsigned char myAccel3lvRead(unsigned char reg)

 unsigned char data = 0; 
 
 myAccelI2C_START(LIS3L02_I2C_ADDR+I2C_WRITE);     // device address 및 write mode 설정
 myAccelI2C_WRITE(reg);

    // 레지스터 설정
 myAccelI2C_START(LIS3L02_I2C_ADDR+I2C_READ);       // device address 및 read mode 설정
   
 data = myAccelI2C_READ_NAK(); 
 myAccelI2C_STOP(); 


 return data;
}

 

//myAccel3LV02의 특정 레지스터에 데이터를 기록
void myAccel3lvWrite(unsigned char reg, unsigned char data)
{
 myAccelI2C_START(LIS3L02_I2C_ADDR+I2C_WRITE);     // device address 및 write mode 설정
 myAccelI2C_WRITE(reg);         // 레지스터 설정
 myAccelI2C_WRITE(data);        // 데이터 출력
 myAccelI2C_STOP();  
}

 

Posted by nexp

댓글을 달아 주세요