Serial1 UART not working before connecting to the Particle cloud

Hello.

Until my Photon is connected to the Particle cloud, Seria1 RX seems not to be working.
It does not receive characters.

However, for all I know, it may not even sending characters.

Any clue on if I am doing something wrong?

Thanks.

Try looking at system modes and/or system threading in the docs :slight_smile:

Hi,

I have enabled the SYSTEM_THREAD(ENABLED) and I am working on the default AUTOMATIC SYSTEM_MODE.

Does it write something that I missed?

I also forgot to mention that I am working with threads.
I raise the thread serial1_task and inside I am having the following:

{code}
os_thread_return_t serial1_task(void param)
{
while (1) {
if (Serial1.available()) {
bb = Serial1.read();
bb_index++;
/
… */
}
delay(10); //not much going on.
}

On a second note, I think that my Photon does nothing until it is connected.
I am not even calling waitUntil(Particle.connected); or waitUntil(WiFi.connected);

What am I doing wrong?

OK solved it!

It seems to me, and perhaps I am wrong here, that any Particle.* function will block anything until Particle is connected to the cloud.

So, before any Particle.* function, I placed in setup a:
while (WiFi.ready() == true);
statement.

Thanks!

@kostbill, even with SYSTEM_THREAD(ENABLE), when SYSTEM_MODE(AUTOMATIC) is selected, the user app will not run until a Cloud connection is achieved. You should consider using SEMI_AUTOMATIC mode and control the connection yourself. BTW, you may want to use waitUntil(Particle.connected) instead of what you show above. :slight_smile:

Not quite.
Most Particle.xxxx() functions will not block code execution even without cloud connection - some may fail (more or less gracefully - e.g. Particle.publish()) but most of them do their job just fine.
The only one that recently "started" to block is Particle.connect() itself.

But with your serial read task (which could be done without a dedicated thread too) I'd do away with that unconditional 10ms delay after each read.

For the bigger picture, we'd need to see more of your code (best a minimal sketch that exherts the undesired behaviour).

Thanks for the replies people!

I used waitUntil(Particle.connected). Unless I am doing something completely wrong, I think this also blocks.

When I go home I will try to make a minimal sketch and post it here.

Thanks people.