411353021
发表于 2012-6-3 22:44
不错哈
<P>不错哈</P>
<P>不错哈</P>
<P>不错哈</P>
<P>不错哈</P>
<P>不错哈</P>
<P>不错哈</P>
<P>不错哈</P>
<P>不错哈</P>
<P>不错哈</P>
<P>不错哈</P>
<P>不错哈</P>
675636624
发表于 2012-6-7 09:37
vvv
:) dddddd
fanyujiang
发表于 2012-6-13 10:31
学习了 哈
chairmanisme
发表于 2012-7-5 17:20
usart1和usart2 中断互相收数据
引用了你的代码,我想usart1输入中断后 发送到usart2,然后usart2通过串口助手发送数据给usart1,;<br>usart1的中断程序参照了你的方法,我在usart2那里可以收到;但是usart2发送数据,usart1就没反应。我的usart2中断程序不想要判断什么帧头 帧尾的,想直接收数据。你看看哪里错了啊<div><div>int main(void)</div><div>{</div><div> SystemInit();</div><div> Rcc_Configuration(); ////系统时钟配置</div><div> NVIC_Configuration();<span class="Apple-tab-span" style="white-space:pre"> </span> //中断向量配置</div><div> UsartGPIO_Configuration();</div><div> USART_Configuration();</div><div><br></div><div> </div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>while(1)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>//<span class="Apple-tab-span" style="white-space:pre"> </span>USART_SendData(USART1, i);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div>}</div></div><div><div>void NVIC_Configuration(void)</div><div>{</div><div> NVIC_InitTypeDef NVIC_InitStructure;<span class="Apple-tab-span" style="white-space:pre"> </span>//定义数据结构体</div><div> </div><div> NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0000);//将中断矢量放到Flash的0地址</div><div><br></div><div> NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//设置优先级配置的模式,详情请阅读原材料中的文章</div><div><br></div><div> //使能串口中断,并设置优先级</div><div> NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;</div><div> NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;</div><div> NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;</div><div> NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; </div><div> NVIC_Init(&NVIC_InitStructure);<span class="Apple-tab-span" style="white-space:pre"> </span>//将结构体丢到配置函数,即写入到对应寄存器中</div><div><br></div><div><br></div><div><br></div><div> //这个参数设置的是,STM32 MCU中43个中断通道的先占优先级</div><div> /* Enable the USART2 Interrupt 串口2 */</div><div> NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;</div><div> NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;</div><div> NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;</div><div> NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;</div><div> NVIC_Init(&NVIC_InitStructure);</div><div><br></div><div> </div><div><br></div><div>}</div></div><div><div>void Rcc_Configuration(void)</div><div>{</div><div><br></div><div> RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO,ENABLE);</div><div>RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);</div><div> RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); </div><div>}</div></div><div>中断:</div><div><div>void USART1_IRQHandler(void)</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>char i=0,j,t;</div><div> //处理接收到的数据</div><div> if(USART_GetITStatus(USART1, USART_IT_RXNE) == SET)</div><div> {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> /* Clear the USART1 Receive interrupt */</div><div> /* USART_ClearITPendingBit(USART1, USART_IT_RXNE);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>com1_buffer=USART_ReceiveData(USART1);<span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>for(j=0;j<=i;j++)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>USART1_Putc(com1_buffer);<span class="Apple-tab-span" style="white-space:pre"> </span> */</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>while(USART1_ReceiveChar()!=0xaa);//寻找帧头</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>t=USART1_ReceiveChar();</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span> while(t!=0xbb)//若是没到帧尾就继续接收</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span> {com1_buffer=t;</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span> t=USART1_ReceiveChar();}</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>for(j=0;j<(i-1);j++)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>USART2_Putc(com1_buffer);//把接收到的数据发送出</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>USART_ClearITPendingBit(USART1,USART_IT_RXNE); //清中断标识</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>if(USART_GetFlagStatus(USART1,USART_FLAG_ORE)==SET)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> //溢出-如果发生溢出需要先读SR,再读DR寄存器 则可清除不断入中断的问题</div><div> {</div><div> USART_ClearFlag(USART1,USART_FLAG_ORE); //读SR</div><div> USART_ReceiveData(USART1); //读DR</div><div> }</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><br></div><div><br></div><div>}</div></div><div>关键是下面的usart2中断,看有问题么</div><div><div>void USART2_IRQHandler(void)</div><div>{<span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>char i=0,j,t;</div><div> //处理接收到的数据</div><div> if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)</div><div> {<span class="Apple-tab-span" style="white-space:pre"> </span> </div><div><span class="Apple-tab-span" style="white-space:pre"> </span> /* Clear the USART1 Receive interrupt */</div><div><br></div><div><br></div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>t=USART2_ReceiveChar();</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span> while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) != SET)//若是没到帧尾就继续接收</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span> {com2_buffer=t;</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span> t=USART2_ReceiveChar();}</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>for(j=0;j<(i-1);j++)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>USART1_Putc(com2_buffer);//把接收到的数据发送出</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>USART_ClearITPendingBit(USART2,USART_IT_RXNE); //清中断标识</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span> //溢出-如果发生溢出需要先读SR,再读DR寄存器 则可清除不断入中断的问题</div><div> if(USART_GetFlagStatus(USART2,USART_FLAG_ORE)==SET)</div><div> {</div><div> USART_ClearFlag(USART2,USART_FLAG_ORE); //读SR</div><div> USART_ReceiveData(USART2); //读DR</div><div> }</div><div><br></div><div><br></div><div><br></div><div>}</div></div><div><br></div><div><br></div><div>请高手指教啊</div>
zhangliyong
发表于 2012-7-9 13:13
hao ziliao hao hao xuexi
hansmmm
发表于 2012-7-9 21:37
ddddddddddddddd
顶了好帖
maclinux
发表于 2012-7-10 00:13
tongwen
ztbzyw1
发表于 2012-7-17 10:46
学习
学习了
电子机器人
发表于 2012-7-19 11:18
谢谢!对我有些帮助
os2
发表于 2012-7-26 07:36
收费的
怎么买啊???
yuexia9bei
发表于 2012-7-26 18:51
感谢楼主啦
冰の水若寒
发表于 2012-7-27 20:25
为啥还要花钱啊?
wang168003
发表于 2012-7-30 15:53
无语。。。坚决不下载
hqf224
发表于 2012-9-16 19:34
垃圾也是收费?还是贡献给初学者!那是欺骗初学者吧 ?
zuiyu
发表于 2012-9-16 22:41
谢谢楼主分享,回帖是种美德
wdliming
发表于 2012-10-4 11:39
不管咋说,下了
lshl1988
发表于 2012-10-14 09:01
楼主不地道,要是都这样,新人还怎么学习啊
shi2999
发表于 2012-10-14 12:52
支持一下
wanseu
发表于 2013-5-3 16:49
回复 21楼 411353021 的帖子
不错学习
victory0702
发表于 2013-5-9 09:49
就这玩意还收费,太搞笑了