有一段程序实现的是把STM32串口的数据通过w5100发到电脑,可是用网口调试助手收不到数据,之前ping是通的,程序不知哪有问题(编译无错误,主要是思想),请大神指点一下。我是想先把一个IO口当UASRT的输入然后w5100发送,测试一下。
其中的中断添加的程序是这样的:(前面先省略)
void TIM3_IRQHandler(void)
{
TIM_Cmd(TIM3,DISABLE);
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
number++;
}
if ((number > 150)&&(biaozhiweier == 0)) //biaozhiweie是为了不让总线没数据也一直向上位机发送
{
sizeofdata = size - 3;
buff[sizeall - size + 1] = sizeofdata;
buff[sizeall - size + 2] = sizeofdata >> 8;
biaozhiweier = 1;
biaozhiwei = 0;
size = 0;
number = 0;
}
TIM_Cmd(TIM3,ENABLE);
}
void USART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1, USART_IT_RXNE)==SET)
{
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
if (biaozhiwei == 0)
{
biaozhiwei = 1;
biaozhiweier = 0;
buff[sizeall++] = 0x80;
buff[sizeall++] = 0x00;
buff[sizeall++] = 0x00;
buff[sizeall++] = USART_ReceiveData(USART1);
size = 4 + size++;
buff;
}
else
{
buff[sizeall++] = USART_ReceiveData(USART1);
size++;
}
number = 0;
}
if (sizeall > 500)
{
memcpy(Tx_Buffer, buff, sizeall);//Tx_Buffer是w5100发送缓存区,buff是串口接收的缓存区
//if (size != 0)
S_tx_process(0, sizeall);
sizeall = 0;
}
if(USART_GetITStatus(USART1, USART_IT_TC)!= RESET)
{
USART_ClearFlag(USART1, USART_FLAG_TC);
}
}
另外GPIO配置如下:(只用到一个IO口只做输入)
void USART1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* config USART1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOD, ENABLE);
/* Configure USART1 Rx (PD.8) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* USART1 mode config */
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_Even ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
}
int main(void)的一部分:
unsigned int number;
unsigned int size;
unsigned char buff[1024];
unsigned int biaozhiwei;
unsigned int biaozhiweier;
unsigned int sizeall;
number = 0;
size = 0;
biaozhiweier = 0;
biaozhiwei = 0;
sizeall = 0;
while(1)
{
if (number > 200)
{
memcpy(Tx_Buffer, buff, size);
S_tx_process(0, size);
size = 0;
number = 0;
}
}
貌似是把源数据开头还要加个什么0x80,也不知道为啥会没反应...求大神指点! |