先刨个坑
等视频上传好了再来填坑,吼吼
使用mx1081的AD模块,采集AD值,然后送wifi发送
使用UDP,简单快速明了,关键是人比较懒
虽然实现了,但是还有很多地方不是很明白
上代码,简单注释了一下main函数回复可见,哇咔咔
#include "stdio.h"
#include "ctype.h"
#include "MX1081_IO.H"
#include "stm32f2xx.h"
#include "platform.h"
#include "mxchipWNET.h"
#define ADC1_DR_Address ((u32)0x4001204C)
void ADC1_CH1_DMA_Config(void);
float AD_value_1;
vu16 ADC_ConvertedValue[2];
#define LowPowerMode
#define AP_NAME "Ljj@Home"
#define AP_PASSWORD "xxxxxxxx"
//我家的密码,就不告诉你,吼吼
#define APP_INFO "mxchipWNet Demo: Wi-Fi Link"
network_InitTypeDef_st wNetConfig;
net_para_st para;
/* ========================================
User provide callback functions
======================================== */
void system_version(char *str, int len)
{
snprintf( str, len, "%s", APP_INFO);
}
void userWatchDog(void)
{
}
void WifiStatusHandler(int event)
{
switch (event) {
case MXCHIP_WIFI_UP:
printf("Station up \r\n");
break;
case MXCHIP_WIFI_DOWN:
printf("Station down \r\n");
break;
case MXCHIP_UAP_UP:
printf("uAP up \r\n");
getNetPara(¶, Soft_AP);
printf("Soft AP mode: IP address: %s \r\n", para.ip);
printf("Soft AP mode: NetMask address: %s \r\n", para.mask);
printf("Soft AP mode: MAC address: %s \r\n", para.mac);
break;
case MXCHIP_UAP_DOWN:
printf("uAP down \r\n");
break;
default:
break;
}
return;
}
void ApListCallback(UwtPara_str *pApList)
{
int i;
printf("Find %d APs: \r\n", pApList->ApNum);
for (i=0;i
ApNum;i++)
printf(" SSID: %s, Signal: %d%%\r\n", pApList->ApList.ssid, pApList->ApList.ApPower);
}
void NetCallback(net_para_st *pnet)
{
printf("Station mode: IP address: %s \r\n", pnet->ip);
printf("Station mode: NetMask address: %s \r\n", pnet->mask);
printf("Station mode: Gateway address: %s \r\n", pnet->gate);
printf("Station mode: DNS server address: %s \r\n", pnet->dns);
printf("Station mode: MAC address: %s \r\n", pnet->mac);
}
void stationModeStart(void)
{
int ret;
memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_st));
wNetConfig.wifi_mode = Station;
strcpy((char*)wNetConfig.wifi_ssid, AP_NAME);
strcpy((char*)wNetConfig.wifi_key, AP_PASSWORD);
wNetConfig.dhcpMode = DHCP_Client;
ret = StartNetwork(&wNetConfig);
printf("connect to %s....., return %d\r\n", wNetConfig.wifi_ssid, ret);
}
void softAPModeStart(void)
{
int ret;
memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_st));
wNetConfig.wifi_mode = Soft_AP;
strcpy((char*)wNetConfig.wifi_ssid, "Soft AP test");
strcpy((char*)wNetConfig.wifi_key, "");
strcpy((char*)wNetConfig.local_ip_addr, "192.168.0.1");
strcpy((char*)wNetConfig.net_mask, "255.255.255.0");
strcpy((char*)wNetConfig.address_pool_start, "192.168.0.10");
strcpy((char*)wNetConfig.address_pool_end, "192.168.0.177");
wNetConfig.dhcpMode = DHCP_Server;
ret = StartNetwork(&wNetConfig);
printf("Setup soft AP: %s, return %d\r\n", wNetConfig.wifi_ssid, ret);
}
vs32 tick = 0;
vs32 button_irq = 0;
void RptConfigmodeRslt(network_InitTypeDef_st *nwkpara)
{
if(nwkpara == NULL){
printf("Configuration failed\r\n");
}
else{
printf("Configuration is successful, SSID:%s, Key:%s\r\n", \
nwkpara->wifi_ssid,\
nwkpara->wifi_key);
}
}
char* itostr(char *str, int i)
{
sprintf(str, "%d", i);
return str;
}
i
void Button_irq_handler(void *arg)
{
printf("Start scanning by user...\r\n");
mxchipStartScan();
}
void ADC1_CH1_DMA_Config(void) //stm32的AD配置,DMA模式
{
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
DMA_InitTypeDef DMA_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
// DMA_DeInit(DMA2_Stream0);
/* DMA2 Stream0 channe0 configuration **************************************/
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC_ConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = 2;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream0, &DMA_InitStructure);
DMA_Cmd(DMA2_Stream0, ENABLE);
/* Configure ADC1 Channe6 pin as analog input ******************************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* ADC Common Init **********************************************************/
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);
/* ADC1 Init ****************************************************************/
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 2;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channe6 configuration *************************************/
ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 1, ADC_SampleTime_3Cycles);
// ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 2, ADC_SampleTime_3Cycles);
/* Enable DMA request after last transfer (Single-ADC mode) */
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
}
本帖最后由 ljj3166 于 2014-11-19 19:24 编辑