Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Serial Communication with PIC Device

Status
Not open for further replies.

mkpriya457

Newbie level 5
Newbie level 5
Joined
Apr 21, 2013
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,367
I am trying to execute the following code in ARM kit. It doesn't show any error in cross compiler. But when it is run in the target it shows segmentation error. Please help why the error occurred?


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <stdio.h>
#include <termios.h>/* POSIX terminal control definitions */
#include <fcntl.h>/* File control definitions */
#include <string.h>
#include "2440addr.h"
#include "2440lib.h"
void GenerateDelay(int);
int value;
int main()
{
  int fd,fs;
  struct termios options,option;
  int n;
  char buff[15];
char k[4];
int i;
 rGPGCON = 0x00000055;  //All the pins of GPJ port is configured as OUTPUT pins
   rGPGUP  = 0x00000000;  //Corresponding bits of the PORTJ, Internal PULLUP is enabled
   rGPGDAT = 0x00000000;  //Initially all the port pins are at LOGIC LOW
  /* Open Port */
  fd = open("/dev/ttySAC1", O_RDWR | O_NOCTTY | O_NDELAY);  /* open the device */
 //fs = open("/dev/ttySAC2", O_RDWR | O_NOCTTY | O_NDELAY); 
 printk(KERN_EMERG"1");
  if(fd == -1)/*Returns the file descriptor on success or -1 on error*/
 {
    printf("ERROR Open Serial Port!");
  }  
 printk(KERN_EMERG"2");
 
//if(fs== -1)
//{
//printf("Error on opening the port");
//}
  /* Serial Configuration */
  tcgetattr(fd, &options);   // Get Current Config
  cfsetispeed(&options, B9600); // Set Baud Rate
  cfsetospeed(&options, B9600);
  options.c_cflag = (options.c_cflag & ~CSIZE) | CS8;//8 bit data 
  options.c_iflag =  IGNBRK;
  options.c_lflag = 0;
  options.c_oflag = 0;
  options.c_cflag |= CLOCAL | CREAD;
  options.c_cc[VMIN] = 1;
  options.c_cc[VTIME] = 5;
  options.c_iflag &= ~(IXON|IXOFF|IXANY);//disable software flow control
  options.c_cflag &= ~(PARENB | PARODD);//no parity
  /* Save The Configure */
  tcsetattr(fd, TCSANOW, &options);
  /* Flush the input (read) buffer */
  tcflush(fd,TCIOFLUSH);
//tcgetattr(fs, &option);   // Get Current Config
  //cfsetispeed(&option, B9600); // Set Baud Rate
  //cfsetospeed(&option, B9600);
  //option.c_cflag = (option.c_cflag & ~CSIZE) | CS8;//8 bit data 
  //option.c_iflag =  IGNBRK;
  //option.c_lflag = 0;
  //option.c_oflag = 0;
  //option.c_cflag |= CLOCAL | CREAD;
  //option.c_cc[VMIN] = 1;
  //option.c_cc[VTIME] = 5;
  //option.c_iflag &= ~(IXON|IXOFF|IXANY);//disable software flow control
  //option.c_cflag &= ~(PARENB | PARODD);//no parity
  /* Save The Configure */
//tcsetattr(fs, TCSANOW, &option);
  /* Flush the input (read) buffer */
  //tcflush(fs,TCIOFLUSH);
int d=0;
 printk(KERN_EMERG"3");
while(1)
{
write(fd,"F",1);//send move forward command to child
rGPGDAT=0x00000a;//make froward movement
 printk(KERN_EMERG"4");
 do{
    n = read(fd,buff,4);   // Read Data From Serial Port
buff[n]=0;
 for(i=0;i<n;i++)
    {
      k[i]=buff[i]; //The string received from child copied
    }
//write(fs,"k[]",4);
//l1:if(buff[0]=='s')//if obstacle detected in forward direction
//{
//write(fd,"s",1);//move backward
//rGPGDAT=0X000000;
//GenerateDelay(5);
rGPGDAT=0X000009;
write(fd,"b",1);
GenerateDelay(5);
write(fd,"l",1);//send move right command to child
rGPGDAT=0X000009;
// }
if(buff[0]=='s')//if obstacle detected in right side
{
do
{n=n+1;
rGPGDAT=0X000006;
write(fd,"l",1);//send move left command to child
}while(buff[0]=='g');
do{
write(fd,"r",1);
rGPGDAT=0x00000005;
}while(n!=0);
write(fd,'f');
goto l1;
}
//else
//{
//rGPGDAT=0x00000a;
//write(fd,"f",1);
//}
//if(buff[0]=='s')//obstacle detected in left side
//{rGPGDAT=0X000006;
//write(fd,"r",1);
//}
//if(buff[0]=='s')//if obstacle detected in right side
//{
//rGPGDAT=0X000006;
//write(fd,"r",1);//send move left command to child
//}
//else
//{
//rGPGDAT=0X00000A;
//write(fd,"f",1);
//}
//if(buff[0]=='s')//if obstacle detected in right side
//{
//rGPGDAT=0X000006;
//write(fd,"r",1);//send move left command to child
//}
 
else
{goto l1;
 
}
//send move right command to child
 }while(strncmp(buff,"stop",4)); // If user says top then Exit
 
}
  close(fd); // Close Port
  return 0; // End Program
}
void GenerateDelay(int value)
{
for(;value>0;value--)
{
;
}
}

 

I am trying to execute the following code in ARM kit.

Elaborate on the ARM kit to which you are referring.

What is the make/model/manufacture of the ARM and development board?

Is this device running an Embedded Linux as an OS?

Is the ARM an S3C2440?

Why is the title, "Serial Communication with PIC Device." Why the reference to PIC Device?

BigDog
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top