I want to transmit three values through uart_putS function. but since the variable that i am passing are char and int type it is showing error as "char" is incompatible with parameter type"char *".
what should i do so that the values that are read and stored in char(int) variable can be transmitted in string format or can be transmitted using uart.
Or optionally - what functions takes a pointer to a block of memory, and a size?
this is my code:
i want to transmit the values of function temp(), memx(), memy() and brake() by using gsm() function i am successful for sending the values of longitude and latitude .i have tried many tricks but nothing worked.please give some suggestion what is wrong in this:
</ #include<lpc214x.h> #include<stdio.h> #include<string.h>
#include "UART.h"
#define PRESET 0x00210600 #define ESC 0x1B #define DONE 0x80000000 #define START 0x01000000 #define buzzer 16 #define crash 24
void gsm( void); void gps(void);
char msg[] ; //msg char msg1[] ; //msg1
unsigned char val1,val2,val3,val4; unsigned int val5=0 , val0 ; unsigned int continuation=0; unsigned int k = 0; unsigned char Key, Gate; unsigned char Buff[50]; char Latt[16]; char Long[16]; unsigned char IE=0; unsigned char Flag,Q,ii,pos,j; char brake;
unsigned char temp(void); unsigned char memx(void); unsigned char memy(void); unsigned char memz(void); unsigned char vibrate(void); unsigned char brakeapplied(void);
void DelayMs(int); void delay(int); void serial_isr (void)__irq;
int main(void)
{ char tem,hor,ver; char vib; unsigned int ADC_CH; unsigned long val[5];
PINSEL0 |= 0x00000005; PINSEL1 |= 0x01 << 24; PINSEL1 |= 0x01 << 26; PINSEL1 |= 0x01 << 28; PINSEL1 |= 0x01 << 18; PINSEL0 |= 0x00000003 ; PINSEL0 |= 0x00000003;
VPBDIV = 0x02; AD0CR = 0x00210602; AD0CR |= 0x01000000;
UART0_Init (9600); UART1_Init (9600);
U0IER = 1;
VICIntSelect = 0<<6; VICVectCntl0 = 0x020 | 6; VICVectAddr0 = (unsigned long)serial_isr; VICIntEnable = 0x00000040;
IODIR1=0x00ff0000;
ADC_CH = 1;
while(1) { while (ADC_CH < 7) { do { val[ADC_CH] = AD0GDR; // Read A/D Data Register } while ((val[ADC_CH] & 0x80000000) == 0); //Wait for the conversion to complete val[ADC_CH] = ((val[ADC_CH] >> 6) & 0x03FF); ADC_CH++; delay(10); AD0CR = PRESET | (1<<ADC_CH); AD0CR |= START; } tem= temp(); hor= memx(); ver= memy(); vib= vibrate(); brake= brakeapplied();
if(ADC_CH >= 7 /*The number of channels used in PS-ARMDPK*/ ) { ADC_CH = 1; AD0CR = PRESET | (1<<ADC_CH); AD0CR |= START;
}
if(tem >= 110 && tem <= 130) { IOSET1 = buzzer ; DelayMs(50); DelayMs(50); IOCLR1 = buzzer; DelayMs(50); DelayMs(50);
if(hor >= 0x55 || ver >= 0x5a ) { IOSET1= buzzer ; DelayMs(50); DelayMs(50); DelayMs(50); DelayMs(50);
IOCLR1= buzzer;
DelayMs(50); DelayMs(50); DelayMs(50); DelayMs(50); }
if(hor >= 0x7f || ver >= 0x7f) { if(vib == 0xff) { IOSET1= crash ; DelayMs(50); DelayMs(50); DelayMs(50); DelayMs(50);
IOCLR1= crash ;
DelayMs(50); DelayMs(50); DelayMs(50); DelayMs(50); } }
if ((IOPIN1 & (1 << 24)) == 0 ) { gps();
gsm(); while ((IOPIN1 & (1<<24)) == 0); }
unsigned char temp() {
unsigned int val0 , t ; U0THR = 0xAB; delay(5); U0THR = 0xB1; delay(5); U0THR = (AD0DR1 >> 6) & 0x03FF;
val0 = U0THR; t= (val0 *0.48876) ;
delay(10);
return(t); }
unsigned char memx() { U0THR = 0xAB; delay(5); U0THR = 0xB2; delay(5); U0THR = (AD0DR2 >> 6) & 0x03FF; delay(5);
val1 = U0THR; delay(10); return(val1);
unsigned char memy() { U0THR = 0xAB; delay(5); U0THR = 0xB3; delay(5); U0THR = (AD0DR3 >> 6) & 0x03FF; delay(5);
val2 = U0THR; delay(10);
return(val2);
unsigned char memz() { U0THR = 0xAB; delay(5); U0THR = 0xB4; delay(5); U0THR = (AD0DR4 >> 6) & 0x03FF; delay(5); val3 = U0THR; delay(10); return(val3); }
unsigned char vibrate() { U0THR = 0xAB; delay(5); U0THR = 0xB5; delay(5); U0THR = (AD0DR5 >> 6) & 0x03FF; delay(5);
val4 = U0THR; delay(10);
return(val4); }
unsigned char brakeapplied() { U0THR = 0xAB; delay(5); U0THR = 0xB6; delay(5); U0THR = AD0DR6 ; delay(5); if(U0THR == 0x1000FFC0 && continuation==0) { val5=val5+1; continuation=1; } if(U0THR != 0x1000FFC0) { continuation=0; }
return(val5); }
---------------------------------------------------------------------------------------
void gsm( void) {
U0IER = 0; UART1_PutS ("AT+CMGS=\"9176235634\"\r"); delay(10); UART1_PutS ("Vechicle Crashed @ \Lattitude,Longitude,Temperature,xf,yf,brake : "); delay(10); UART1_PutS (Latt); delay(10); UART1_PutS (Long); delay(10); /*here i want to transmit tem,hor,ver,brake values give any idea */ UART1_PutC (0x1A); delay(10); U0IER = 1; } ------------------------------------------------------------------------------------------ void gps() { if (Flag == 2) { if (Key == 'A' || Key == 'L') { Flag = 1;
} else { Flag = 0; } }
if ((Key == 'G' || Key == 'L') && Q == 0) { Flag = 2;
if (Flag == 1) { Q = 1; Gate = 0;
Buff[ii] = Key; while (!Gate); ii++; if (ii > 35)//(*(Buff+i) == '*') { IE = 1; U0IER = 0; Q = 0; Flag = 0;
pos = 13; j = 0; while (j<10) { Latt[j] = Buff[pos]; pos++; j++; } Latt[j] = '\0';
pos = 25; j=0; while (j < 10) { Long[j] = Buff[pos]; pos++; j++; } Long[j] = '\0';
strcpy (msg, "Lat: "); strcpy (msg1,"Lon: ");
j = 0; while (j<10) { msg[j+5] = Latt[j]; msg1[j+5] = Long[j]; j++; }
ii=0;
IE = 0; U0IER = 1; } } }
void serial_isr (void)__irq {
char Msg;
if(((Msg = U0IIR) & 0x01) == 0) { switch (Msg & 0x0E) { case 0x04: while (!(U0LSR & 0x20)); while (IE); Key = U0RBR; Gate = 1; break; case 0x02: break; default : break; } } VICVectAddr = 6;
void delay(int a) { int k,l; for(k=0;k<=100;k++) for(l=0;l<=a;l++); }
void DelayMs(int b) { int k,l; for(k=0;k<=50;k++) for(l=0;l<=b;l++); }
All I see is random garbled garbage.
Did you notice the posting instructions for source code?
#include<lpc214x.h> #include<stdio.h> #include<string.h> #include "UART.h" #define PRESET 0x00210600 #define ESC 0x1B #define DONE 0x80000000 #define START 0x01000000 #define buzzer 16 #define crash 24 void gsm( void); void gps(void); char msg[] ; //msg char msg1[] ; //msg1 unsigned char val1,val2,val3,val4; unsigned int val5=0 , val0 ; unsigned int continuation=0; unsigned int k = 0; unsigned char Key, Gate; unsigned char Buff[50]; char Latt[16]; char Long[16]; unsigned char IE=0; unsigned char Flag,Q,ii,pos,j; unsigned char temp(void); unsigned char memx(void); unsigned char memy(void); unsigned char memz(void); unsigned char vibrate(void); unsigned char brakeapplied(void); void DelayMs(int); void delay(int); void serial_isr (void)__irq; int main(void) { char tem,hor,ver,vib,brake; unsigned int ADC_CH; unsigned long val[5]; PINSEL0 |= 0x00000005; PINSEL1 |= 0x01 << 24; PINSEL1 |= 0x01 << 26; PINSEL1 |= 0x01 << 28; PINSEL1 |= 0x01 << 18; PINSEL0 |= 0x00000003 ; PINSEL0 |= 0x00000003; VPBDIV = 0x02; AD0CR = 0x00210602; AD0CR |= 0x01000000; UART0_Init (9600); U0IER = 1; VICIntSelect = 0<<6; VICVectCntl0 = 0x020 | 6; VICVectAddr0 = (unsigned long)serial_isr; VICIntEnable = 0x00000040; IODIR1=0x00ff0000; ADC_CH = 1; while(1) { while (ADC_CH < 7) { do { val[ADC_CH] = AD0GDR; } while ((val[ADC_CH] & 0x80000000) == 0); val[ADC_CH] = ((val[ADC_CH] >> 6) & 0x03FF); ADC_CH++; delay(10); AD0CR = PRESET | (1<<ADC_CH); AD0CR |= START; } tem= temp(); hor= memx(); ver= memy(); vib= vibrate(); brake= brakeapplied(); if ((IOPIN1 & (1 << 24)) == 0 ) { gps(); gsm(); while ((IOPIN1 & (1<<24)) == 0); } } } unsigned char temp() { U0THR = (AD0DR1 >> 6) & 0x03FF; val0 = U0THR; delay(10); return(val0); } unsigned char memx() { U0THR = (AD0DR2 >> 6) & 0x03FF; delay(5); val1 = U0THR; delay(10); return(val1); } unsigned char memy() { U0THR = (AD0DR3 >> 6) & 0x03FF; delay(5); val2 = U0THR; delay(10); return(val2); } unsigned char memz() { U0THR = (AD0DR4 >> 6) & 0x03FF; delay(5); val3 = U0THR; delay(10); return(val3); } unsigned char vibrate() { U0THR = (AD0DR5 >> 6) & 0x03FF; delay(5); val4 = U0THR; delay(10); return(val4); } void gsm( void) { U0IER = 0; UART1_PutS ("AT+CMGS=\"9176235634\"\r"); delay(10); UART1_PutS ("Vechicle Crashed @ \n Lattitude,Longitude,Temperature,xf,yf,brake : "); delay(10); UART1_PutS (Latt); delay(10); UART1_PutS (Long); delay(10); UART1_PutC (0x1A); delay(10); U0IER = 1; } void gps() { if (Flag == 2) { if (Key == 'A' || Key == 'L') { Flag = 1; } else { Flag = 0; } } if ((Key == 'G' || Key == 'L') && Q == 0) { Flag = 2; } if (Flag == 1) { Q = 1; Gate = 0; Buff[ii] = Key; while (!Gate); ii++; if (ii > 35)//(*(Buff+i) == '*') { IE = 1; U0IER = 0; Q = 0; Flag = 0; pos = 13; j = 0; while (j<10) { Latt[j] = Buff[pos]; pos++; j++; } Latt[j] = '\0'; pos = 25; j=0; while (j < 10) { Long[j] = Buff[pos]; pos++; j++; } Long[j] = '\0'; strcpy (msg, "Lat: "); strcpy (msg1,"Lon: "); j = 0; while (j<10) { msg[j+5] = Latt[j]; msg1[j+5] = Long[j]; j++; } ii=0; IE = 0; U0IER = 1; } } }