最近买了一个正点原子SIM900A模块做一个彩信发送BMP图,使用串口调试助手加载图片发送,手机能收到图片,并打开。写了一个小程序,把图片BMP编码,用程序配合战舰STM32发,结果手机收到了,但是打不开,会出现如下结果
unsigned char hua[54] = { //BMP文件头
0X42,0x4D,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,
0x00,0x28,0x00,0x00,0x00,0x0A,0x00,0x00,0x00,0x0A,0x00,0x00,0x00,
0x01,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0xCA,0x00,0x00,0x00,0x20,
0x2E,0x00,0x00,0x20,0x2E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00
};
//摄像头发彩信实验
int main(void)
{
unsigned int i=0,j;
delay_init(); //延时函数初始化
NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
uart_init(9600); //串口初始化为9600
usart3_init();
LED_Init(); //LED端口初始化
MQ2_Init(); //烟雾传感器初始化
while(sim900a_cmd("AT\r","OK",1000) != SIM900A_TRUE)//SIM900A检测
{
printf("\r\n模块响应测试不正常!!\r\n");
printf("\r\n若模块响应测试一直不正常,请检查模块的连接或是否已开启电源开关\r\n");
}
printf("\r\n通过了模块响应测试,开始彩信测试...\r\n");
while(1)
{
if(!GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_6)) //烟雾传感器报警信号
{
if(n)
{
gprs_Init();
while(i<sizeof(hua)) //发送BMP头
{
SIM900A_TX(hua);
delay_us(1);
i++;
}
for(i=0;i<10;i++) //读取数据 读取10*10的图片大小
{
for(j=0;j<10;j++)
{
SIM900A_TX(0X00);
delay_us(1);
SIM900A_TX(0X7C);
delay_us(1);
}
}
SIM900A_TX(0X00);
delay_us(1);
SIM900A_TX(0X00);
delay_us(1);
gprs_end();
}
}
n=GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_6);
delay_us(1);}
void gprs_Init(void)
{
SIM900A_TX("AT+CMMSINIT\r"); //初始化彩信功能
DelaySec(1);
while(sim900a_cmd("AT+CMMSINIT\r","OK",1000) != SIM900A_TRUE);
// SIM900A_TX("AT+CMMSCURL=\"mmsc.myuni.com.cn\"\r");//联通号
SIM900A_TX("AT+CMMSCURL=\"mmsc.monternet.com\"\r");//移动号
DelaySec(1);
SIM900A_TX("AT+CMMSCID=1\r"); //设置承载上下文ID
DelaySec(1);
SIM900A_TX("AT+CMMSPROTO=\"10.0.0.172\",80\r");//设置mms协议属性
DelaySec(1);
SIM900A_TX("AT+CMMSSENDCFG=6,3,0,0,2,4\r");//设置mms的发送参数
DelaySec(1);
SIM900A_TX("AT+SAPBR=3,1,\"Contype\",\"GPRS\"\r");//激活承载
DelaySec(1);
SIM900A_TX("AT+SAPBR=3,1,\"APN\",\"CMWAP\"\r");
DelaySec(1);
SIM900A_TX("AT+SAPBR=1,1\r");
DelaySec(1);
SIM900A_TX("AT+SAPBR=2,1\r");
DelaySec(1);
// SIM900A_TX("AT+CMMSEDIT=0\r");//关闭编辑状态,这样在模块的buff区的数据将被删除
// DelaySec(1);
SIM900A_TX("AT+CMMSEDIT=1\r");//打开编辑状态,这个状态才可以发送mms
DelaySec(1);
SIM900A_TX("AT+CMMSDOWN=\"PIC\",256,40000\r");
DelaySec(1);
while(sim900a_cmd("AT+CMMSDOWN=\"PIC\",256,40000\r","CONNECT",1000) != SIM900A_TRUE);
}
void gprs_end(void)
{
SIM900A_TX("AT+CMMSRECP=\"15681171836\"\r");//发送的号码,自己修改
DelaySec(1);
SIM900A_TX("AT+CMMSSEND\r");//发送mms
DelaySec(107);
DelaySec(107);
DelaySec(107);
DelaySec(107);
while(sim900a_cmd("AT+CMMSSEND\r","OK",1000) != SIM900A_TRUE);
SIM900A_TX("AT+CMMSEDIT=0\r");//退出配置模式
DelaySec(1);
SIM900A_TX("AT+SAPBR=0,1\r");//退出承载
DelaySec(1);
SIM900A_TX("AT+CMMSTERM\r");//退出彩信功能
DelaySec(1);
}
不知道问题在哪儿,求解
|