- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
I try to receive some parameter through UART and convert them into int, but when I try to assign the conversion value to the internal registers, there is a error message; I guess I missed something important about the data type, can anyone give me some suggestion? Thank you!
char * string;
int parameter = 0;
while(string = UART_szGetParam()) {
for (j=0; j<4; j++)
UART_CPutString(" <");
UART_PutString(string); // Print each parameter
UART_CPutString(">\r\n");
}
parameter = atoi(string); // this is where get error message
!E main.c(278): operands of = have illegal types `array 7 of char' and `int'
!E main.c(278): lvalue required
make: *** [obj/main.o] Error 1
- Labels:
-
PSoC 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Look at the string you are giving to atoi(). it should be ascii numeric chars followed by a
NULL char to terminate string. If it has non ascii numerics in it, like delimiter chars, then
it will choke.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You get a compile error which we cannot see from where it is caused. Please attach the complete project. Use Cypress Designer -> File -> Archive Project and attach the resulting file.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bob,
Thank you for replying. Its my first time to use forum, do you know how can I attach the project files here?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you post there is an Add Attachments link below text entry area, you pick that,
navigate to where file is, select it, then pick upload link, then click submit when you
have finished rest of post.
Regards, Dana..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem is not the string conversion with atoi(), but your try to assign to a char* a value. your line 164 in your file which is flagged as error shows
offset = rs485_parameter;
where offset is declared (line 88) as char offset[7] = "offset"; //1
and
int rs485_parameter = 0;
Which really will not match.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bob,
I see. I defined the string with same name to the global variable name. Thank you so much for the help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That was an easy one, so you are always welcome!
Bob