PIC18F25K22 UART ERROR

For general Flowcode discussion that does not belong in the other sections.
Post Reply
SILVESTROS
Posts: 90
http://meble-kuchenne.info.pl
Joined: Tue Dec 13, 2022 9:04 pm
Has thanked: 24 times
Been thanked: 1 time

PIC18F25K22 UART ERROR

Post by SILVESTROS »

I try to send some strings to pc port with uart..chip not run,,,maybe config error ..code in another chip runs ok...can i use XT 16MHZ? what is the configuration for that chip? Is there some hardware modification in that case ( pin RE3/MCLR to HIGH? ) ?
Attachments
PIC18F25K22_DEMO1.fcfx
(16.04 KiB) Downloaded 374 times

chipfryer27
Valued Contributor
Posts: 1221
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 300 times
Been thanked: 430 times

Re: PIC18F25K22 UART ERROR

Post by chipfryer27 »

Hi

You could run at potentially any speed you want that the chip supports including Internal Oscillator, meaning no external components are required. I think that chip can support up to 64MHz from internal sources if using 4xPLL. Page 26 of datasheet gives info on what internal clocks can be used.

However if you use the internal oscillator you will need to add in a C-Code block at the very beginning of your chart to configure. At present you appear to be using an external 4MHz clock. Personally I would use internal.

I see you have both the UART and ESP8266 components both on channel 1 which means they would share the same connections and won't work, they need to be different. That chip supports two UARTS so choose a different channel for the ESP.

In your chart you are sending strings out on the UART and the UART is probably doing as you ask.

For example you send string "x"

This will send the actual character x out as it is enclosed with quotation marks ( "x" )

The use of quotation marks when sending a string means send this as text . To send a variable omit the quotation marks. However your variable x is defined as a byte, not a string, so can only contain a numeric value between 0-255. Also it isn't initialised so when your program starts it could possibly be at any random value. It is good practise to initialise all variables as you create them so the program starts with known values.

Later you attempt a calculation using send string "x+1" which actually sends the characters x+1 as they are enclosed in quotation marks.

You could try the following.

In Build>Project Options set your oscillator to Internal Oscillator Port Functions on RA6, RA7 and set clock speed to 8MHz (or whatever you choose based on p26)
Under Component Libraries>Runtime choose IntOsc Helper
Once on your chart, in Properties set clock speed to 8MHz (or whatever clock you chose)
This provides the necessary C-Code to set the oscillator. Copy this code (e.g. OSCCON=0x60; )
Place a C-Code Icon as your very first icon in your chart and paste the code obtained from above step (note you can delete any existing code in block or paste afterwards)

Edit your variables to initialise x as 0. Now x will always start with the value of 0.

When you want to send the value of variable x, use Send Number x
To increase the value of x by 1 insert a calculation icon with x=x+1

Do note that you have a delay of 100mS in your loop which means you will send out ten values per second (not really but for sake of discussion you will). As your variable x is a byte it will increase to 255 in around 25 seconds then rollover to 0 and increase again.

You didn't mention if whatever you connected to received any communications. If so what? I'm guessing it received the characters as described above.

Let us know how you get on.

Regards

SILVESTROS
Posts: 90
Joined: Tue Dec 13, 2022 9:04 pm
Has thanked: 24 times
Been thanked: 1 time

Re: PIC18F25K22 UART ERROR

Post by SILVESTROS »

many thanks for help!
the codes for 2 PIC that controls 2 ESP8266 runs ok..data are recorded well in Excel with Data Streamer..
PIC18F46K22 controls first ESP8266, gets data from sensors , is set as client (STA), and send data with wifi to second ESP...PIC18F25K22 controls second ESP , gets sensors data from first ESP , is set as server (AP), and send data to pc..the only that need the set of codes, is the kind of variables that holds sensors data...
the problem is that in client code , ESP8266 component has 2 ways to send variables..SendString and SetOutValue...those variables send as string, but data variables are Z (INT)...the same for the server code, where data variables are send to pc as Number..communication between 2 ESP is ok..how can set correct data variables in 2 codes, to send data from first ESP to second ?
Attachments
ESP8266_AP_PIC18F25K22.fcfx
(22.76 KiB) Downloaded 378 times
ESP8266_STA_PIC18F46K22_SENSORS.fcfx
(21.07 KiB) Downloaded 375 times

chipfryer27
Valued Contributor
Posts: 1221
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 300 times
Been thanked: 430 times

Re: PIC18F25K22 UART ERROR

Post by chipfryer27 »

Hi

With reference to your chart that is gathering sensor data.

It was quite a while back that I last used the ESP8266 and I think I used "AT" commands rather than the component, so I'm not 100% on it's use.

However I notice you are trying to send the string variable dataSEN with a length of 20 characters. This variable has not been initialised so could possibly be anything. Initialise it with 2 x double quotation marks (""). Also you don't actually assign any value to it at all anywhere in your chart.

I assume you want this to represent all the sensor data you gathered, which is x/y/z from accelerometer and your oximeter data. The accelerometer data is an integer number between -32768 and +32767 for each axis and each of your oximeter variables are between 0 and 65535

I also assume that as Excel DS is the target you will be sending as CSV.

Therefore you must assign your string enough characters to hold everything. Each axis could hold six characters and each oximeter reading could hold five characters to say nothing of commas and any other info that is required. Therefore you will need to increase the string length from 20 to something more appropriate. As the data and commas could be 32 characters in length plus any control characters that may need to be included, 36 would be a minimum if you were to send everything in a single string.

Next, you need to create the string to send and for that you need to do some calculations to turn your sensor data into strings. Personally, until I get things working I like to see every calculation to ensure everything is OK and then perhaps shorten.

Create five new String variables, perhaps call them x,y,z,hr and ox and remember to initialise ("").

After you have collected all your sensor readings insert a calculation icon. Here we will convert you numeric values to strings
To do that you use the ToStrings() calculation so to convert the xaxis data to a string you would have x=ToString$(xaxis)
Do that for all your sensor data

Next you need to concatenate them with a comma between each value. Lets assume x= 1234 and y= 5678
In another calculation box clear your dataSEN with dataSEN = "" this is to ensure any previous values held are gone.
Then to build your string you would have
dataSEN = dataSEN+x which adds string x to dataSEN. Now dataSEN = "1234"
Now you need to insert your comma so dataSEN = dataSEN+"," and this now makes dataSEN= "1234,"
Now add y so that we now have dataSEN= "1234,5678"
Add in another comma and continue until you have entered all your values. No need for a comma after your last reading is entered.

Now you will have a string of comma separated values, for example:-
dataSEN = "1234,5678,9012,12345,54321"

dataSEN could now be sent using the ClientSendRequest or SendString commands depending on how things need to be done.

As mentioned I'm not 100% on using the 8266 especially attempting to create a datalink between them, and you may need to create sockets. Have a look at the WiKi examples

https://www.flowcode.co.uk/wiki/index.p ... etworking)

Let us know how you get on.

I'll try and have a look at the ESP8266's over the next few days.

Regards

EDIT...
Forgot to say that after you add your last data value do a further calculation to add "\r\n" to give (as per example)
dataSEN = "1234,5678,9012,12345,54321\r\n"

SILVESTROS
Posts: 90
Joined: Tue Dec 13, 2022 9:04 pm
Has thanked: 24 times
Been thanked: 1 time

Re: PIC18F25K22 UART ERROR

Post by SILVESTROS »

I made some changes at codes...I have no data in Data Streamer. I noticed that data in DS are recorded only as Number...not as INT or strings..communication between 2 ESP is ok...the problem is the way that data are send to second ESP..how can I send data string to second ESP , and how can I convert the received data to Numbers array ?
Attachments
ESP8266_AP_PIC18F25K22.fcfx
(22.91 KiB) Downloaded 377 times
ESP8266_STA_PIC18F46K22_SENSORS.fcfx
(30.59 KiB) Downloaded 391 times

chipfryer27
Valued Contributor
Posts: 1221
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 300 times
Been thanked: 430 times

Re: PIC18F25K22 UART ERROR

Post by chipfryer27 »

Hi

In the tests I did a week or so ago, I found that Excel DS accepts ascii characters. Numbers and text can be sent to DS and received / displayed. I could easily create and send strings to Excel as documented in those posts. 12345 / 12345.67 / -12345 / ABCdef can all be sent / displayed.

I would start with the sensor board and ensure it is sending what is required, then look at the receiving board etc before moving to Excel.

If you have a TTL serial to USB convertor, connect it to your PC then directly to your UART of your sensor board. Run a terminal program (e.g. Terminal / PuTTY) and make sure the strings documented in my posts above are being received

Regards

SILVESTROS
Posts: 90
Joined: Tue Dec 13, 2022 9:04 pm
Has thanked: 24 times
Been thanked: 1 time

Re: PIC18F25K22 UART ERROR

Post by SILVESTROS »

Hi and thanks for help.
I've tested the hardware... 2 boards are ok. the receiver board with second ESP + PIC18F25K22 is connected with serial/USB module (FT232) to PC..communication between PIC and PC is ok.. I've tested with a demo code..PIC has 2 uarts.. uart1 is connected to module, uart2 is connected with RX/TX to ESP.. I don't know if that will works, but I think that there is no communication between 2 ESP. . ret var is 0 ..something in two codes is missing or it is wrong in section of sending and receiving of data...there is no problem with sending data to excel, not to collect data from sensors..in simulator, string variable of sensors data is ok .I use RealTerm and PuTTY to check the received data but there is no data.. I can't find an example on how can connect 2 ESP with wifi, and send/receive data..only at arduino, that I can't use, because of small space of mobile board..I made some corrections in codes with no result..

chipfryer27
Valued Contributor
Posts: 1221
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 300 times
Been thanked: 430 times

Re: PIC18F25K22 UART ERROR

Post by chipfryer27 »

Hi

When I get a chance I will look at the ESPs.

Once I know that I have both "talking" I would probably start by using the RxInt component on UART1. This generates an interrupt upon receipt of data. In my associated Interrupt handler macro I would just receive the byte and immediately send it out on UART2 to the PC.

Again, I would confirm each stage before moving on.

Regards

SILVESTROS
Posts: 90
Joined: Tue Dec 13, 2022 9:04 pm
Has thanked: 24 times
Been thanked: 1 time

Re: PIC18F25K22 UART ERROR

Post by SILVESTROS »

Hi,
Below are some photo of hardware and sensors to take a look...I'll continue to try to find errors , or to use another component...I was added a force sensor (FSR).
Attachments
1677521113843.jpg
1677521113843.jpg (86.41 KiB) Viewed 14033 times
IMG_20230227_185656.jpg
IMG_20230227_185656.jpg (85.77 KiB) Viewed 14036 times
IMG_20230227_185238.jpg
IMG_20230227_185238.jpg (95.65 KiB) Viewed 14036 times
Last edited by SILVESTROS on Mon Feb 27, 2023 6:18 pm, edited 2 times in total.

chipfryer27
Valued Contributor
Posts: 1221
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 300 times
Been thanked: 430 times

Re: PIC18F25K22 UART ERROR

Post by chipfryer27 »

Hi

My 8266's are a bit more basic than yours appear to be :)

I don't think the sensors are of any issue as I'm sure the interfacing will be straight forward.

What distance do you need to communicate over? I ask as I recently made a transparent Bluetooth link that would do as you require.

https://www.matrixtsl.com/mmforums/view ... 68&t=23028

I should get time to look at the ESPs in a day or so.

Regards

Post Reply