Omlouvám se Pityy, měl jsem rodinné problémy tak jsem se k učení nedostal. Ale Teď už mám čas, prosím je ještě ochota mi pomoci?
Já to vidím tak že programování 32bProcesorů se asi dělá úplně jinak než jsem zviklí z 8bProcesorů.
Celý program:
[code]
#include <stddef.h>
//#include “stm32l1xx.h”
#include “defs.h”
#include “delay.h”
#include “systick.h”
/volatile int32_t sysInterval;
RCC_ClocksTypeDef clocks;/
void sysTickService(void);
//void sysTickInit(void); // initializes system timer to 1ms overflow
void rccInit(void);
void gpioInit(void);
void tim4Init(void);
/void sysTickInit(void);
void intervalDec(void);
void delayMs(int32_t time);/
int main(void)
{
int i = 0;
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32l1xx_md.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32l1xx.c file
*/
// 2Mz int. RC
gpioInit();
tim4Init();
sysTickInit(&sysTickService);
RCC_ClocksTypeDef clks;
RCC_GetClocksFreq(&clks);
// Default systick clk source is HCLK/1
// SysTick_CLKSourceConfig makes no changes.
// Systick timer works withouth prescaller
// (Diode using it is 8x faster)
//SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
//SysTick_Config(clks.HCLK_Frequency / 8000);
// work correctly
SysTick_Config(clks.HCLK_Frequency / 8000);
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
//rccInit();
//delayMs(500);
/* Infinite loop */
while (1)
{
i++;
delayMs(500);
IO_NEG(LD_PORT, LD_GREEN);
IO_NEG(LD_PORT, LD_BLUE);
}
return 0;
}
void gpioInit(void)
{
// enable io clock
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_InitTypeDef initStr;
initStr.GPIO_Pin = LD_GREEN;// | LD_BLUE;
initStr.GPIO_Mode = GPIO_Mode_OUT;
initStr.GPIO_OType = GPIO_OType_PP;
initStr.GPIO_PuPd = GPIO_PuPd_NOPULL;
initStr.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(LD_PORT, &initStr);
IO_HIGH(LD_PORT,LD_GREEN);
//IO_LOW(LD_PORT,LD_BLUE);
initStr.GPIO_Pin = BT;
initStr.GPIO_Mode = GPIO_Mode_IN;
//initStr.GPIO_OType = GPIO_OType_PP;
initStr.GPIO_PuPd = GPIO_PuPd_NOPULL;
initStr.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(BT_PORT, &initStr);
/*GPIOA->MODER = 0; // mode: IN/OUT/ALT/ANA
GPIOA->OTYPER = 0; // O type: PP/OD
GPIOA->OSPEEDR = 0; // O speed: 400k/2m/10m/40m
GPIOA->PUPDR = 0; // pull: none/up/down/reserved
GPIOA->IDR; // input
GPIOA->ODR = 0; // output
GPIOA->BSRRL = 0; // bSet
GPIOA->BSRRH = 0; // bReset
GPIOA->LCKR = 0; // lock
GPIOA->AFR[0] = 0; // AF[b7:0]
GPIOA->AFR[1] = 0; // AF[b15:8]
*/
}
void rccInit(void)
{
//
RCC_HSICmd(ENABLE);
FLASH_ReadAccess64Cmd(ENABLE);
// can be check that 64-bit access is taken into account by reading FLASH_ACR here
FLASH_SetLatency(FLASH_Latency_1);
// can be check that the new number of WS is taken into account by reading FLASH_ACR here
FLASH_PrefetchBufferCmd(ENABLE);
while (RESET == RCC_GetFlagStatus(RCC_FLAG_HSIRDY))
; // wait for HSI startup
RCC_HCLKConfig(RCC_SYSCLK_Div4); // Clk/4
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); // 16MHz
// final: 4MHz
SystemCoreClockUpdate();
}
void tim4Init(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); // tim4 clk enable
TIM_TimeBaseInitTypeDef tBinit;
tBinit.TIM_ClockDivision = TIM_CKD_DIV1;
tBinit.TIM_CounterMode = TIM_CounterMode_Down;
tBinit.TIM_Period = 99;
tBinit.TIM_Prescaler = 9999;
TIM_TimeBaseInit(TIM4, &tBinit);
TIM_OCInitTypeDef tOinit;
tOinit.TIM_OCMode = TIM_OCMode_Toggle;
tOinit.TIM_OCPolarity = TIM_OCPolarity_High;
tOinit.TIM_OutputState = TIM_OutputState_Enable;
tOinit.TIM_Pulse = 0; // OC event on timer reset
TIM_OC1Init(TIM4, &tOinit);
//TIM_SetCounter(TIM4, 99);
TIM_Cmd(TIM4, ENABLE);
// pin config
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
GPIO_InitTypeDef initStr;
initStr.GPIO_Pin = LD_BLUE;
initStr.GPIO_Mode = GPIO_Mode_AF;
initStr.GPIO_OType = GPIO_OType_PP;
initStr.GPIO_PuPd = GPIO_PuPd_NOPULL;
initStr.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(LD_PORT, &initStr);
GPIO_PinAFConfig(LD_PORT, GPIO_PinSource6, GPIO_AF_TIM4);
}
void sysTickService(void)
{
//
#ifdef DELAY_H_
delayIntervalDec();
#endif
}[/code]
Jestli to dobře chápu tak třeba toto je definice vstupu a vystupů:
[code]GPIO_InitTypeDef initStr;
initStr.GPIO_Pin = LD_GREEN;// | LD_BLUE;
initStr.GPIO_Mode = GPIO_Mode_OUT;
initStr.GPIO_OType = GPIO_OType_PP;
initStr.GPIO_PuPd = GPIO_PuPd_NOPULL;
initStr.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(LD_PORT, &initStr);
IO_HIGH(LD_PORT,LD_GREEN);
//IO_LOW(LD_PORT,LD_BLUE);
initStr.GPIO_Pin = BT;
initStr.GPIO_Mode = GPIO_Mode_IN;
//initStr.GPIO_OType = GPIO_OType_PP;
initStr.GPIO_PuPd = GPIO_PuPd_NOPULL;
initStr.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(BT_PORT, &initStr);[/code]
Kde LD_GREN je zelená LED
LD_BLUE je modrá, ale ta je za // takže není definovaná
potom BT je vstup je to tlacitko USER
Prosím rozumím tomu dobře?
Dále jsem chtěl dát podmínku např při stisknutí tlačítka, že zelená led bude blikat pomaleji:
[code]if((GPIOA->IDR & BT) != 0x0)
{
delayMs(5000);
IO_NEG(LD_PORT, LD_GREEN);
}
else
{
delayMs(500);
IO_NEG(LD_PORT, LD_GREEN);
IO_NEG(LD_PORT, LD_BLUE);
}[/code]
Ale právě to už mi při krokování nefunfuje? Nevím kde je chyba