Skip to content

Commit

Permalink
test success
Browse files Browse the repository at this point in the history
at25512 success
usart pwm it success
led success
pwm time is not right
  • Loading branch information
wsy984655628 committed Aug 15, 2015
1 parent 4bfdf08 commit 85c35b9
Show file tree
Hide file tree
Showing 40 changed files with 2,057 additions and 5,232 deletions.
2 changes: 1 addition & 1 deletion Myprogram/program/drivers/at25512.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void AT25512_ReadData(unsigned short Addr , unsigned char *data , unsigned char
AT25512_Lower_CS();
SPI2_SendByte(AT25512_READ);
SPI2_SendByte(Addr>>8);
SPI2_SendByte(Addr&0x0F);
SPI2_SendByte(Addr&0xFF);
for(i=0;i<Len;i++)
data[i]=AT25512_Read();
AT25512_Raise_CS();
Expand Down
3 changes: 2 additions & 1 deletion Myprogram/program/drivers/pwm.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "pwm.h"

uint16_t ch[6]={0,1500,1500,1500,1500,1000};


void PwmInit(void)
{
Expand Down Expand Up @@ -28,7 +29,7 @@ void PwmInit(void)
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = 5000;
TIM_TimeBaseStructure.TIM_Prescaler = 90;
TIM_TimeBaseStructure.TIM_Prescaler = 45;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

//TIM2:Channel 1
Expand Down
90 changes: 39 additions & 51 deletions Myprogram/program/drivers/usart.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,38 +62,39 @@ void USART2_DT_Config(void)
DMA_Init(DMA1_Stream5,&DMA_InitStructure);

//DMA command
// USART_DMACmd(USART2,USART_DMAReq_Tx,ENABLE);
// USART_DMACmd(USART2,USART_DMAReq_Rx,ENABLE);
USART_DMACmd(USART2,USART_DMAReq_Tx,ENABLE);
USART_DMACmd(USART2,USART_DMAReq_Rx,ENABLE);

//enable the USART2 Interrupt
USART_ITConfig(USART2,USART_IT_TC,ENABLE);
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&NVIC_InitStructure);

DMA_Cmd(DMA1_Stream6,ENABLE);
// //enable the USART2 Interrupt
// USART_ITConfig(USART2,USART_IT_TC,ENABLE);
// USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
// NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
// NVIC_Init(&NVIC_InitStructure);
//
// //enable the tx DMA interrupt
// DMA_ITConfig(DMA1_Stream6,DMA_IT_TC,ENABLE);
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
// NVIC_InitStructure.NVIC_IRQChannel=DMA1_Stream6_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
// NVIC_Init(&NVIC_InitStructure);
//
// //enable the rx DMA interrupt
// DMA_ITConfig(DMA1_Stream5,DMA_IT_TC,ENABLE);
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
// NVIC_InitStructure.NVIC_IRQChannel=DMA1_Stream5_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
// NVIC_Init(&NVIC_InitStructure);
//enable the tx DMA interrupt
DMA_ITConfig(DMA1_Stream6,DMA_IT_TC,ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel=DMA1_Stream6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&NVIC_InitStructure);

//enable the rx DMA interrupt
DMA_ITConfig(DMA1_Stream5,DMA_IT_TC,ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel=DMA1_Stream5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&NVIC_InitStructure);

//enable the rx dma
DMA_Cmd(DMA1_Stream5,ENABLE);
}

void USART2_DMA_SendData(void)
Expand All @@ -106,27 +107,14 @@ void USART2_DMA_ReceiveData(void)
DMA_Cmd(DMA1_Stream5,ENABLE);
}





int fputc(int ch, FILE *f)
{
/* 发送一个字节数据到USART2 */
USART_SendData(USART2, (uint8_t) ch);

/* 等待发送完毕 */
while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);

return (ch);
}

/// 重定向c库函数scanf到USART1
int fgetc(FILE *f)
void USART2_Print( const char *str )
{
/* 等待串口1输入数据 */
while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);

return (int)USART_ReceiveData(USART2);
int Len = strlen(str);
int i=0;
for(i=0;i<Len;i++)
{
while( RESET == USART_GetFlagStatus(USART2,USART_FLAG_TXE));
USART_SendData(USART2,(uint16_t)str[i]);
}
}

5 changes: 4 additions & 1 deletion Myprogram/program/drivers/usart.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

#include"stm32f4xx.h"
#include <stdio.h>
#include <string.h>

#define USART_SendBuffer_Size 500
#define USART_SendBuffer_Size 10

extern uint8_t USART_SendBuffer[USART_SendBuffer_Size];
extern uint8_t USART_ReceiveBuffer[USART_SendBuffer_Size+100];

void USART2_DT_Config(void);
void USART2_DMA_SendData(void);
void USART2_DMA_ReceiveData(void);

void USART2_Print( const char *str );
int fputc(int ch, FILE *f);
int fgetc(FILE *f);

Expand Down
39 changes: 27 additions & 12 deletions Myprogram/program/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,40 @@
#include "at25512.h"


static void Delay(__IO u32 nCount);
int main()
{
uint8_t test[2]={0x05,0x09};
uint8_t test2[2]={0x01,0x08};

LED_GPIO_Config();
USART2_DT_Config();
// PwmInit();
// Timer5Init();
SPI2_Init();
AT25512_SPI_GPIO_Config();
PwmInit();
Timer5Init();
// Receive_Config();
// SPI2_Init();


GPIO_ResetBits(GPIOC, GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3);
//USART2_DMA_SendData();
USART_SendData(USART2, 'A');
printf(" test \r\n");
{
uint16_t i;
for (i=0; i<USART_SendBuffer_Size; i++)


// USART2_DMA_SendData();
for(;;)
{
USART_SendBuffer[i]= 0x11 ;
AT25512_PageWrite(0x00000,test,4);
LED1(OFF);
Delay(0xFFFFF);
AT25512_ReadData(0x00000,test2,4);
USART_SendBuffer[0]=test2[1];
USART2_DMA_SendData();
LED1(OFF);
Delay(0xFFFFF);
}
}
USART_DMACmd(USART2,USART_DMAReq_Tx,ENABLE);

}

static void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
46 changes: 23 additions & 23 deletions Myprogram/program/stm32f4xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,27 @@ void EXTI15_10_IRQHandler(void)
}
}

//void DMA1_Stream6_IRQHandler(void)
//{
// if(DMA_GetITStatus(DMA1_Stream6,DMA_IT_TCIF6)==SET)
// {
// DMA_ClearITPendingBit(DMA1_Stream6,DMA_IT_TCIF6);
// DMA_Cmd(DMA1_Stream6,DISABLE);
// }
//}
//void DMA1_Stream5_IRQHandler(void)
//{
// if(DMA_GetITStatus(DMA1_Stream6,DMA_IT_TCIF5)==SET)
// {
// DMA_ClearITPendingBit(DMA1_Stream6,DMA_IT_TCIF5);
// USART2_DMA_ReceiveData();
// }
//}
//void USART2_IRQHandler(void)
//{
// if(USART_GetITStatus(USART2,USART_IT_TC)==SET)
// USART_ClearITPendingBit(USART2,USART_IT_TC);
// if(USART_GetITStatus(USART2,USART_IT_RXNE)==SET)
// USART_ClearITPendingBit(USART2,USART_IT_RXNE);
//}
void DMA1_Stream6_IRQHandler(void)
{
if(DMA_GetITStatus(DMA1_Stream6,DMA_IT_TCIF6)==SET)
{
DMA_ClearITPendingBit(DMA1_Stream6,DMA_IT_TCIF6);
DMA_Cmd(DMA1_Stream6,DISABLE);
}
}
void DMA1_Stream5_IRQHandler(void)
{
if(DMA_GetITStatus(DMA1_Stream6,DMA_IT_TCIF5)==SET)
{
DMA_ClearITPendingBit(DMA1_Stream6,DMA_IT_TCIF5);
USART2_DMA_ReceiveData();
}
}
void USART2_IRQHandler(void)
{
if(USART_GetITStatus(USART2,USART_IT_TC)==SET)
USART_ClearITPendingBit(USART2,USART_IT_TC);
if(USART_GetITStatus(USART2,USART_IT_RXNE)==SET)
USART_ClearITPendingBit(USART2,USART_IT_RXNE);
}

Loading

0 comments on commit 85c35b9

Please sign in to comment.