Skip to content

Commit e0a9aea

Browse files
author
Maarten Pennings
committed
0.5.7
- Added example `aospi_bringup.ino`. - Text correction in `readme.md`; added _level shifter pull-ups issue_.
1 parent 3ea035f commit e0a9aea

File tree

10 files changed

+220
-8
lines changed

10 files changed

+220
-8
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// aospi_bringup.ino - test if communication between MCU and OSP node is operational
2+
/*****************************************************************************
3+
* Copyright 2024 by ams OSRAM AG *
4+
* All rights are reserved. *
5+
* *
6+
* IMPORTANT - PLEASE READ CAREFULLY BEFORE COPYING, INSTALLING OR USING *
7+
* THE SOFTWARE. *
8+
* *
9+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
10+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
11+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
12+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
13+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
14+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
15+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
16+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
17+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
18+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
19+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
20+
*****************************************************************************/
21+
#include <aospi.h>
22+
23+
24+
/*
25+
DESCRIPTION
26+
This sketch just sends a RESET telegram to a node. We check whether that
27+
node forwards the telegram. The checking is done using a logic analyzer.
28+
A next step is sending INITBIDIR.
29+
30+
HARDWARE
31+
The demo runs on the OSP32 board. Add a pull-ups on SION and SIOP of OUT,
32+
and connect a logic analyzer them.
33+
In Arduino select board "ESP32S3 Dev Module".
34+
35+
BEHAVIOR
36+
See readme.md for how to capture and analyze the telegrams.
37+
38+
OUTPUT
39+
Nothing printed to Serial; check the logic analyzer.
40+
*/
41+
42+
43+
const uint8_t reset[] = {0xA0, 0x00, 0x00, 0x22}; // RESET(000)
44+
const uint8_t initbidir[] = {0xA0, 0x04, 0x02, 0xA9}; // INITBIDIR(001)
45+
46+
47+
void setup() {
48+
aospi_init();
49+
}
50+
51+
52+
void loop() {
53+
aospi_tx( reset, sizeof reset );
54+
delayMicroseconds(150);
55+
aospi_tx( initbidir, sizeof initbidir );
56+
delay(1000);
57+
}
136 KB
Loading
28.3 KB
Loading
28.5 KB
Loading
31.2 KB
Loading
4 KB
Binary file not shown.

examples/aospi_bringup/readme.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Bring-up
2+
3+
This project helps checking if an MCU communicates with an OSP node.
4+
5+
6+
## Introduction
7+
8+
When bringing up an OSP based system, the first hurdle is to get communication
9+
established, most notably between the MCU and the first node. The obvious
10+
way to detect successful communication is to switch on an LED of the node.
11+
12+
However, this requires not only successful communication, but also a correct
13+
sequence of telegrams (assign address, clear errors, switch to active state,
14+
set drive current, set PWM value).
15+
16+
In this sketch we just send a RESET telegram to one node, and check whether
17+
that node forwards it.
18+
19+
An optional next step is sending INITBIDIR. Remember that a node needs
20+
150 μs for executing a RESET; a delay for that needs to precede the
21+
INITBIDIR telegram.
22+
23+
24+
## Hardware
25+
26+
The demo runs on the OSP32 board. We cut a MiniBridge cable in two, plug it
27+
in OUT, add a pull-up on SION and SIOP, and connect a logic analyzer.
28+
An alternative is to use the OUT pin header to solder a header or even
29+
directly pull-ups. Recommended pull-up value is 10kΩ.
30+
31+
![hardware setup](extras/hardware.jpg)
32+
33+
The two pull-ups configure the port for USE mode (aka CAN mode).
34+
Unlike the standard LVDS mode, this uses voltage levels to communicate,
35+
so easier to capture using a logic analyzer.
36+
37+
38+
## Logic analyzer
39+
40+
We used a [Saleae](https://www.saleae.com/) logic analyzer.
41+
It even has a slicer for Manchester. These are the settings for the slicer.
42+
43+
![Slicer settings](extras/slicer.png)
44+
45+
46+
## Software
47+
48+
Run the `aospi_bringup.ino` sketch (compile for "ESP32S3 Dev Module" and upload).
49+
It will send a RESET and INITBIDIR every second. Arm the Saleae for a capture
50+
to create a trace. The resulting [trace](extras/trace.sal) has two telegrams,
51+
one for RESET, one for INITBIDIR.
52+
53+
54+
## RESET trace
55+
56+
The first trace captures the RESET telegram.
57+
58+
![reset trace](extras/reset.png)
59+
60+
The MCU sends `A0 00 00 22` to SIO1 of the node, and we see that the
61+
node indeed forwards the same bytes to the (non-existent) next node.
62+
We can use `OSP_aospi\python\telegram` to draw the telegram.
63+
64+
```
65+
(env) OSP_aospi\python\telegram>run A0 00 00 22
66+
+---------------+---------------+---------------+---------------+
67+
byteval | A0 | 00 | 00 | 22 |
68+
byteix |0 0 0 0 0 0 0 0|1 1 1 1 1 1 1 1|2 2 2 2 2 2 2 2|3 3 3 3 3 3 3 3|
69+
bitix |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|
70+
bitval |1 0 1 0 0 0 0 0|0 0 0 0 0 0 0 0|0 0 0 0 0 0 0 0|0 0 1 0 0 0 1 0|
71+
+-------+-------+-----------+---+-+-------------+---------------+
72+
field |preambl| address | psi | command | crc |
73+
bin | 1010 | 0000000000 | 000 | 0000000 | 00100010 |
74+
hex | 0xA | 0x000 | 0x0 | 0x00 | 0x22 (ok) |
75+
meaning | - | broadcast | 0 | reset | 34 (ok) |
76+
+-------+-------------------+-----+-------------+---------------+
77+
```
78+
79+
This proves that the node is operational: it receives a telegram from the MCU
80+
and processes it (forwards it).
81+
82+
83+
## INITBIDE trace
84+
85+
Even more convincing is the trace of the INITBIDIR.
86+
The MCU sends `A0 04 02 A9` to SIO1, this means INITBIDIR(001),
87+
i.e. init and assign yourself address 001
88+
89+
```
90+
(env) OSP_aospi\python\telegram>run A0 04 02 A9
91+
+---------------+---------------+---------------+---------------+
92+
byteval | A0 | 04 | 02 | A9 |
93+
byteix |0 0 0 0 0 0 0 0|1 1 1 1 1 1 1 1|2 2 2 2 2 2 2 2|3 3 3 3 3 3 3 3|
94+
bitix |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|
95+
bitval |1 0 1 0 0 0 0 0|0 0 0 0 0 1 0 0|0 0 0 0 0 0 1 0|1 0 1 0 1 0 0 1|
96+
+-------+-------+-----------+---+-+-------------+---------------+
97+
field |preambl| address | psi | command | crc |
98+
bin | 1010 | 0000000001 | 000 | 0000010 | 10101001 |
99+
hex | 0xA | 0x001 | 0x0 | 0x02 | 0xA9 (ok) |
100+
meaning | - | unicast(1) | 0 | initbidir | 169 (ok) |
101+
+-------+-------------------+-----+-------------+---------------+
102+
```
103+
104+
The outgoing telegram is different.
105+
106+
![reset trace](extras/initbidir.png)
107+
108+
We see the bytes `A0 08 02 F9`; when we plot that we get the following diagram.
109+
110+
```
111+
(env) OSP_aospi\python\telegram>run A0 08 02 F9
112+
+---------------+---------------+---------------+---------------+
113+
byteval | A0 | 08 | 02 | F9 |
114+
byteix |0 0 0 0 0 0 0 0|1 1 1 1 1 1 1 1|2 2 2 2 2 2 2 2|3 3 3 3 3 3 3 3|
115+
bitix |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|
116+
bitval |1 0 1 0 0 0 0 0|0 0 0 0 1 0 0 0|0 0 0 0 0 0 1 0|1 1 1 1 1 0 0 1|
117+
+-------+-------+-----------+---+-+-------------+---------------+
118+
field |preambl| address | psi | command | crc |
119+
bin | 1010 | 0000000010 | 000 | 0000010 | 11111001 |
120+
hex | 0xA | 0x002 | 0x0 | 0x02 | 0xF9 (ok) |
121+
meaning | - | unicast(2) | 0 | initbidir | 249 (ok) |
122+
+-------+-------------------+-----+-------------+---------------+
123+
```
124+
125+
Note that the outgoing telegram is INITBIDIR(002), so we see that the
126+
node has actively transformed the incoming telegram: stepped the address,
127+
and recomputed the checksum.
128+
129+
This means we have successful MCU-SAID communication.
130+
131+
132+
## Afterthought
133+
134+
There are many things that can go wrong. See this libraries readme for a list
135+
of [issues](https://github.com/ams-OSRAM/OSP_aospi?tab=readme-ov-file#issues).
136+
137+
(end)

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=OSP 2wireSPI aospi
2-
version=0.5.6
2+
version=0.5.7
33
author=ams-OSRAM
44
maintainer=ams-OSRAM
55
sentence=A library that implements 2-wire SPI towards and from OSP nodes.

readme.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ File > Examples > OSP 2wireSPI aospi > ...
9696
(adding the fast forwarding time for each intermediate node).
9797
The second aspect is the impact of longer telegrams.
9898

99+
- **aospi_bringup** ([source](examples/aospi_bringup))
100+
This sketch just sends a RESET telegram to a node. We check whether that
101+
node forwards the telegram. The checking is done using a logic analyzer.
102+
A next step is sending INITBIDIR. It is an example of how to bring-up
103+
new hardware/software. There is a more detailed [readme.md](readme.md) to
104+
explain the process.
105+
99106

100107
## API
101108

@@ -126,7 +133,7 @@ Here is a quick overview:
126133
`aospi_txrx_hops(...)` returns an estimate of the number of hops (telegram
127134
forwards by intermediate nodes) that were needed by the last `aospi_txrx()`.
128135

129-
- To testing the (OSP32) PCB the following functions are provided. The first pair
136+
- To test the (OSP32) PCB the following functions are provided. The first pair
130137
`aospi_outoena_set(...)`/`aospi_outoena_get()` allows testing the control line of
131138
the output enable of the outgoing level shifter, the second pair
132139
`aospi_inoena_set(...)`/`aospi_inoena_get()` allows testing the control line of
@@ -223,6 +230,7 @@ Some issues controlling OSP nodes deserve above normal attention.
223230
They are discussed in various sections of this document.
224231

225232
- RESET issue
233+
- level shifter pull-ups issue
226234
- missing SSEL issue
227235
- dual master issue
228236
- different modes issue
@@ -266,12 +274,18 @@ SAID, dedicated to sending. This level shifter has several roles.
266274
The level shifter used on the OSP32 board is unidirectional,
267275
but that is not very relevant.
268276

269-
If the MCU has 5V SPI lines, a level shifter is not needed. However, the
270-
second (dual masters) and third bullet (_RESET issue_) still need to be
277+
If the MCU has 5V SPI lines, level shifting is not needed. However, the
278+
second (_dual masters_) and third bullet (_RESET issue_) still need to be
271279
covered. Both could be covered with a buffer. Another option is to
272280
reconfigure the MCU pins after an SPI transaction, switching them to
273281
tri-state.
274282

283+
**Warning:** some level shifters have internal pull-ups. This leads to
284+
a problem related to the _RESET issue_, the _level shifter pull-ups issue_.
285+
If the level shifter has internal pull-ups on the lines that connect to
286+
the SIO port, then, after a power on, the port will be configured for
287+
CAN mode, effectively blocking the node from receiving any message.
288+
275289

276290
### Two level shifters for receiving
277291

@@ -320,7 +334,7 @@ the MOSI and SCLK line as inputs is sufficient).
320334
### No level shifters - 5V MCU
321335

322336
When the MCU is 5V, there is no reason to have level shifters.
323-
However, the RESET issue and dual master issue still need to be solved.
337+
However, the _RESET issue_ and _dual master issue_ still need to be solved.
324338
This could be solved by replacing the OUT level shifter by an external buffer
325339
with tri-state output. If that one is controlled via the OENA line, there is
326340
no need to change the library. The IN (either from BiDir or Loop) is 5V
@@ -348,7 +362,7 @@ The left-most column assumes a 3V3 MCU, and thus uses level shifters.
348362
The three architectures in this column are supported by the aospi lib.
349363

350364
The center column assume a 5V MCU, so no level shifters are needed.
351-
However due to the RESET issue and dual master issue, a buffer with tri-state
365+
However due to the _RESET issue_ and _dual master issue_, a buffer with tri-state
352366
is needed. For BiDir and Loop only rows, no mux is needed, so the IN buffers
353367
can be avoided in the lower two rows. The three architectures in the center
354368
column are supported by the aospi lib.
@@ -681,6 +695,10 @@ The figure below shows details of the INITLOOP command and response.
681695
682696
## Version history _aospi_
683697
698+
- **2024 November 29, 0.5.7**
699+
- Added example `aospi_bringup.ino`.
700+
- Text correction in `readme.md`; added _level shifter pull-ups issue_.
701+
684702
- **2024 October 22, 0.5.6**
685703
- Telegram dissector (`python\telegram`) now shows casting mode.
686704
- Replaced clock tapping mechanism in `aospi.cpp`; from ISR to polling (faster).
@@ -729,7 +747,7 @@ The figure below shows details of the INITLOOP command and response.
729747
- **2024 July 7, 0.4.0**
730748
- Arduino name changed from `OSP 2-wire SPI - aospi` to `OSP 2wireSPI aospi`.
731749
- Added link for traces.
732-
- Added blue slave line in BiDir diagram (`dirbidir.drawio.png`) and green dashed OSP32 border line in OPS32 diagram (`dirosp32.drawio.png`).
750+
- Added blue slave line in BiDir diagram (`dirbidir.drawio.png`) and green dashed OSP32 border line in OSP32 diagram (`dirosp32.drawio.png`).
733751
- Renamed dir `extra` to `extras`.
734752
- Small corrections in readme.md.
735753
- Added (for board testing) `aospi_outoena_set()`/`aospi_outoena_get()` and `aospi_inoena_set()`/`aospi_inoena_get()`.

src/aospi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
// Identifies lib version
30-
#define AOSPI_VERSION "0.5.6"
30+
#define AOSPI_VERSION "0.5.7"
3131

3232

3333
// OSP uses telegrams of max 12 bytes

0 commit comments

Comments
 (0)