"Software Serial Library" Behavior in LowPower.clockMode (CLOCK_MODE_32MHz)

Asked 1 months ago, Updated 1 months ago, 3 views

SPRENSENSE Arduino IDE (Ver1.8.16) is programming using the Software Serial Library.

Setting LowPower.clockMode (CLOCK_MODE_32MHz) and lowering the operating clock to 32MHz will prevent normal communication.
If you remove this setting and do not specify the clock mode, the communication is successful.
Speed is 115200 bps.

Does the "Software Serial Library" in Spresense have any restrictions on clock mode settings?
No specific description was found in the web developer information.
We are developing a battery-powered system and are trying to reduce power consumption as much as possible by operating it at CLOCK_MODE_32 MHz.
I would appreciate it if you could give me some advice.
(Added on December 17)
We measured the Tx waveform at each mode setting with an oscilloscope.
As a result, CLOCK_MODE_32 MHz deviates the transmission pulse from 115200 bps.
(1) Clock mode, normal
Normal operation
(2) Clock mode settings:CLOCK_MODE_32MHz
Enter a description of the image here
This clock shift may be the cause of the failure to communicate properly.
Isn't it a library bug?

spresense arduino

2022-09-30 11:33

1 Answers

SoftwareSerialIf you look inside the library, it looks like you are adjusting the time with bitDelay.The CPU clock is adjusting the delay, so lowering the CPU clock at CLOCK_MODE_32 MHz may not be supported.

https://github.com/sonydevworld/spresense-arduino-compatible/blob/master/Arduino15/packages/SPRESENSE/hardware/spresense/1.0.0/libraries/SoftwareSerial/SoftwareSerial.cpp#L238

void SoftwareSerial::begin(long speed)
{
  unsigned long bitDelay;

  pinMode(_transmitPin, OUTPUT);
  pinMode(_receivePin, INPUT_PULLUP);

  /* 4-cycle delays (must never be 0!)*/
  bitDelay=(clockCyclesPerMicrosecond()*250000)/speed;
  _tx_delay = bitDelay-16;
  _rx_delay_centering=bitDelay+(bitDelay/2)>160?bitDelay+(bitDelay/2)-160:1;
  _rx_delay_intrabit = bitDelay-16;

However, if you adjust the bitDelay by yourself while looking at the waveform in the oscilloscope, it will also work at CLOCK_MODE_32 MHz.Please give it a try.


2022-09-30 11:33

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.