EEProm stores commands and settings
BL2322 is a simple and effective way to use I2C devices with any computer and OS. Fully built RS232/USB adaptors are available.
Table Of Contents
Features
Applications
*Programmable
*1 Description
*2 Table 1: BL232 Pinout Description
*3 I2C Busses
*3.1 Bit Timing
*3.2 SCL Stretch
*3.3 Four Wire Bus
*3.4 Fast Mode
*3.5 Multimaster Arbitration
*4 Table 2: Command Character List
*5 Command Format
*5.1 A simple I2C Transaction
*5.2 Stop
*5.3 Reading I2C
*5.3.1 Reading an indeterminate number of bytes: Pascal Strings
*5.4 10 Bit Addresses
*5.5 R and W: Fast Read/Write Commands
*5.6 Selecting the I2C Bus
*5.7 Delaying
*5.8 Pause Command for Timing Critical Sequences
*5.9 I2C Acknowledge
*5.9.1 Writing
*5.9.2 Reading
*6 Status and Control Registers
*6.1 Setting Control Register and Bus Timing
*6.2 Querying Status Register
*6.3 Return a Char
*7 Message Numbers
*8 Other I/O Modes
*8.1 Direct Pin I/O
*8.2 SPI Write
*9 EEProm Memory
*9.1 Table 3: EEProm Memory Map
*9.2 Macros
*9.3 A Macro for combined 8 switches + 8 Leds board
*9.4 A simple "program"
*9.5 Writing the EEProm
*9.5.1 Write Protecting the EEProm
*9.6 Dumping the EEProm
*10 Serial Comms
*10.1 EOL and Separator Chars
*10.2 Data Format
*10.3 Baud Rate
*10.3.1 Special Pins Mode
*10.4 Max Baud Rate and Speed
*10.4.1 PC Serial Port Latency
*10.4.2 RS232 Drivers
*10.5 Serial Buffer Size
*10.6 Handshaking
*10.7 Table 4: Serial Initalisation Registers in EEProm
*10.8 USB
*11 Oscillator
*11.1 Timer
*12 Watchdog
*13 Sleep Mode
*14 Example Applications
*14.1 Dual Interface USB & RS232 to I2C Adaptor
*14.2 Simple I2C to RS232 Adaptor
*14.3 Simple Data logger with no PC Software
*14.4 Isolating an I2C Bus
*14.5 RS232 to LCD Module adaptor
*14.6 Huge RS232 Parallel Port
*14.7 Hardware Watchdog for Network Server
*15 Ordering Information
*16 Co-operation
*
Name |
DIP Pin # |
SSOP Pin # |
I/O/P Type |
Buffer Type |
User Pin |
Description |
Bit # |
SCL1 |
17 |
19 |
I/oc |
ST |
I/0 |
I2C Bus #1 |
1 |
SDA1 |
18 |
20 |
I/oc |
ST |
I/0 |
I2C Bus #1 |
0 |
SCL2 |
1 |
1 |
I/oc |
ST |
I/0 |
I2C Bus #2 |
2 |
SDA2 |
2 |
2 |
I/oc |
ST |
I/0 |
I2C Bus #2 |
3 |
SDA5In |
3 |
3 |
In |
ST |
I/oc |
Used as SDAIn in 4 wire mode |
4 |
_Reset_ |
4 |
4 |
In |
ST |
In |
||
Vss |
5 |
5,6 |
|||||
Int |
6 |
7 |
In |
ST |
I/0 |
8 |
|
RXD |
7 |
8 |
In |
ST |
-- |
RS232 data IN, Connect to PC TXD |
9 |
TXD |
8 |
9 |
Out |
-- |
RS232 data Out, Connect to PC RXD |
10 |
|
CTS |
9 |
10 |
Out |
I/0 |
Connect to PC CTS, Tells PC to send |
11 |
|
RTS SCL4 |
10 |
11 |
IN oc |
TTL |
I/0 |
Connect to PC RTS, PC controls me. Used as SCL4 when handshake disabled |
12 |
SDA4 |
11 |
12 |
I/O |
TTL |
I/0 |
User pin / SDA4 |
13 |
SCL3 |
12 |
13 |
TTL |
I/0 |
14 |
||
SDA3 |
13 |
14 |
TTL |
I/0 |
15 |
||
VDD |
14 |
15,16 |
|||||
X2 Out |
15 |
17 |
Crystal / Oscillator Out |
||||
X1 In |
16 |
18 |
Crystal / Oscillator In |
The BL232 supports up to 4 physical 2 wire I2C Busses. (1-4)
Two operate with Schmitt-CMOS levels, and 2 with TTL levels.
Only one bus can be active at one time. The bus will be put into Stop (P) state before selecting the new bus.
Bus numbers above 4 are logical busses, ie they map to the same pins as another bus.
Bus 5 is the 4 wire bus.
Bus 6 uses FAST (400kHz) timing.
Timing complies with the specs for standard 100kHz I2C. To slow the bus you may load another value into the I2Ctiming byte.
see 6.1:Setting Control Register and Bus Timing
SCL Stretch is supported. On most busses it is implemented on a bit-by-bit basis. On Fast and Hs Busses, it tested at the start of a cycle, or S or P states.
Why test at the Start when the slave asserts stretch at the end of a cycle?
The stretch is asserted by the slave after the ACK, however it does not impact the master until it attempts to begin the next byte/S/P.
SCL Stretch should be asserted for <10ms. Clock stretch will timeout after approx. 218/fXtal secs. (17ms @ 14.7MHz)
It is significantly easier to isolate a bus when the transmit and receive are split. A 4 wire logical bus can be used where galvanic isolation is required.
For most applications where SCL stretch is not used, 2 isolators are needed from the BL232, and only a single return SDA isolator.
You can use a single IL716 magnetic coupler from NVE.
Note that it is often easier to isolate the RS232 bus.
Bus 1 can also be operated in Fast Mode (400kb). This improves throughput somewhat when high baud rates are used.
There is no support for multimaster. BL232 assumes it is the only master on the bus. Where multiple masters are desired on a bus, for example in a ATE set, I/O pins can be used to handshake between masters, or to reset/disable the other master when the BL232 wants the bus.
Char |
Command |
Chars to Follow |
|||
0-9 A-F |
Hex |
1-∞ |
lower case a-f are NOT hex |
||
: |
PauseUntilEOL |
Pause execution until EOL char received. (except in EE, see below) |
5.8 |
||
;
: |
ReturnToRS232IfChars
ForceReturnToRS232 |
Execution returns to RS232 buffer if there are chars in buffer, otherwise continues in EE Execution unconditionally returns to RS232 buffer if in EE |
|||
< |
Return |
0 |
Execution returns from a macro, either to calling macro or RS232 buffer |
||
= |
unused |
||||
> |
Jump to EE |
2 |
Execution jumps to macro in EE |
||
? |
Query Status |
0 |
returns status register |
6.2 |
|
@ |
unused |
||||
G |
Set Bus Number |
1- |
Sets the I2C Bus to use. Will execute STOP (P) before changing bus. |
5.6 |
|
H |
Hi-speed start |
Future Use |
|||
I |
Check Interrupt |
I |
Checks Int pin, and execute Int macro if enabled |
||
J |
Write Control Flags & Timing |
6.1 |
|||
K |
|||||
L |
Delay NNNN ms |
Dnnnn |
4 |
5.7 |
|
M |
Set Message Number |
Mnn |
0,2 |
7 |
|
N |
|||||
O |
Output Direct to Pins |
1-∞ |
write direct to pins and tri-state registers |
8.1 |
|
P |
I2C Stop |
P |
0 |
5.2 |
|
Q |
Query Direct from Pins |
Q |
0 |
Reads pins directly |
8.1 |
R |
Read nn bytes |
Rnn |
2 |
Reads bytes from previous address (I2C) or SPI |
5.5 |
S |
I2C Start |
S |
0-∞ |
5.1 |
|
T |
Type Char |
Tnn… |
2-∞ |
Types data back |
6.3 |
U |
Dump EEProm |
U |
0 |
Dumps whole EEProm |
9.6 |
V |
Write EEProm |
Vaadd… |
Write eeprom from address aa |
9.5 |
|
W |
Write |
Wdd… |
Writes bytes to previous address (I2C) or SPI |
5.5 |
|
X |
Software Reset |
||||
Y |
SPI Write |
Write successive bytes to an SPI |
8.2 |
||
Z |
sleep |
13 |
|||
, |
(comma) ignored |
||||
(space) ignored |
|||||
0x80 0xFF |
Chars>=0x80 are used as ASCII |
||||
The BL232 uses a simple printable Ascii format. Hex characters are used for all data and I2C addresses. Other characters are used as single char commands. Unrecognised chars are generally ignored.
Chars are generally processed and acted on immediately.
The basic form follows that shown in the Philips I2C documentation.
Consider writing 0xD7 to a Philips PCF8574 8 bit Port. The base address is 0x40.
Send:
S40D7P
[I2C Start][Address:0x40][Data:0xD7][I2C Stop]
The command S sends an I2C Start. P is an I2C Stop, just like the Philips documents.
To send a string of 80/81/80..… to the port:
Repeated Start:
S 40 80 81 S 82 S83 P
P returns the I2C bus to the idle state. You should leave the bus stopped when it is idle. Interrupts and other automatic actions need the bus to be stopped, so they don't split an indivisible operation
The adaptor looks at bit 0 (R/W bit) of the address byte. If 1, this is a read.
To read, set bit 0 of the address eg: read 2 successive bytes from address 0x40
S410A
[I2C start][Address:0x40 R/W=Read][Number Bytes to read: 10 (0x0A)]
The adaptor replies with 0x83 both times:
8383[eol]
Repeated Start:
S407D,S4101,P
7D[eol]
[start][write 0x7D][repeated start][read 1 byte][stop] [adaptor returns 1 byte)]
Due to the way the I2C bus works, (master controls reads), the master has to know how many bytes to read. If the device is returning an indeterminate number, eg a string, then we have a problem.
The BL232 has support for reading pascal style strings. If the NumberOfBytes is 0, then it will take the first byte read from the I2C slave, to be the string length.
eg an I2C slave (0x40) has the string "Hi", ie 0x 02 48 49
S4100
4849[eol]
Carefully study the Philips notes on 10 bit addressing. In short: you write 2 address bytes, so any read is done by a write(2 address bytes), then a read, with only the first address byte.
The R and W commands are particularly useful with 10 bit addresses to reduce traffic.
Where you want to read or write to the previous address use R and W. eg instead of
S4083 S4101 S407D P S407E S4101 P
Using R and W to read and write the previous addresses is much shorter.
S4083 R01 W7D W7E R01 P
10 Bit addresses will be correctly handled.
U selects the I2C Bus. If the bus is not in the stop (P) state, then the adaptor will execute a P before changing the bus.
Busses 1-4 are separate busses. Busses > 4 use the same pins in different ways
S4083 U2 S4084 U1
[Write 0x83 to PCF8574 on Bus1][Select Bus 2][Send 84 to another 8574 on Bus2][return to bus 1]
Multiple I2C Busses allows you to have more of one type of chip than sub addressing allows. (eg 24 PCF8574's).
Bus # |
SDA |
SCL |
SDA In |
SCLIn |
Fast |
|
1 |
18 |
17 |
||||
2 |
1 |
2 |
||||
3 |
13 |
12 |
||||
4 |
11 |
10 |
||||
5 |
11 |
10 |
3 |
-- |
||
Some bus numbers use some or all the same pins as another bus.
To output a pulse we can use Delay (L). Delay is up to 65535 milliseconds.
S4001 L0400 W00
[Set bit0 of PCF8574 HI][Delay 0x400ms ie ~1 sec][Set bit 0 LO]
':' (colon) pauses execution until an EOL char (CR or LF) is received. Chars after the ':' are stored in the buffer, but not processed until an EOL char is received. This ensures that the sequence of operations between ':' and EOL will always take the same time, irrespective of baud rate or undefined computer delays.
:S4001 L0001 W00 [eol]
[pulse bit0 high for 1ms]
Obviously the string between ':' and EOL must fit in the RX buffer.
Read the Philips I2C documentation closely.
At the end of each byte transfer there is an acknowledge.
When writing the slave generates NACK. (pulls the bus LOW)
If the slave does not nack, then either
Most hardware designs and hardware type I2C slaves are deterministic.
For this reason the default is to ignore nack. You can check the result of the last write by QueryStatus. This is an easy way to check the bus for I2C devices at power on.
Two fControl flags offer more sophisticated nack handling
fControl |
|||
Bit |
Rst |
Name |
Description |
3 |
1 |
WrIgnoreNack |
makes I2C write routines ignore nack. The interface will continue to write bytes to the bus even after a nack. Writes halt when nack occurs. Subsequent bytes are ignored. Write "N" back to host |
1 |
0 |
AckWrites |
writes K/N as each byte written to I2C is/not acknowledged by the slave "K" nack'd OK "N" failed to nack Writes nothing |
When reading from a slave the nack is generated by the master (BL232) as each byte is received.
The I2C Bus requires that after receiving the last byte a master doesn't nack. This signals end-of-data to the slave.
The BL232 handles this automatically.
However you might wish to read a large number of bytes from a slave (eg >255), or read as a series of shorter blocks, without signalling end-of-data to the slave.
In this case you can set the flag fControlReadBlockNack. In this case all reads will be nack'd, and you must take care of the last read yourself.
fControl |
|||
Bit |
Default |
Name |
Description |
7 |
|||
6 |
|||
5 |
RxWatchdogEnable |
enables the watchdog on rx chars |
|
4 |
InterruptEnable |
enables interrupt response |
|
3 |
WrIgnoreNack |
makes I2C write routines ignore nack |
|
2 |
RdBlockNack |
nack won't be sent when last byte is read |
|
1 |
AckWrites |
writes K/N as each byte written to I2C is/not acknowledged by the slave |
|
0 |
0 |
MessageNumsEnabled |
enables return of message numbers |
fStatus |
||||
Bit |
Default |
Name |
Description |
|
7 |
||||
6 |
||||
5 |
||||
4 |
Int |
Current state of Interrupt pin (0=active int) |
||
3 |
* |
TimerTimedOut |
||
2 |
* |
FifoOverflow |
Either RX or TX fifo overflowed |
|
1 |
* |
ClkStrechTimeout |
I2C timed out waiting for SCL to go Hi |
|
0 |
Nack |
result of last I2C Nack |
To set the control register
J [control register]
To change the I2C Bus timing. 0 is fastest, 255 is very slow.
J [control register] [I2C Timing]
eg Enable Interrupts
J04
eg Enable Ints and set I2Ctiming to 15
J040F
? returns the status register. This is most commonly used to check NACK to see if the last write was acknowledged by the slave
T types a char back to the PC.
S407D T563D R01
V=7D[eol]
[set 8574 to 0x7D][Type "V=" back to PC][reads 8574: 0x7D]
Message Numbers provide a way of dealing with latency. The message number is 8 bits
Without message numbers it can be difficult to pair up commands and returned data, especially when long latencies are involved. eg
S407D R01 D0100 R01
7D[eol]7D[eol]
If we turn on message numbers, and set the message number to 0x05
S407D M05 R01 D0100 R01 D0100 R01
057D[eol]067D[eol]077D[eol]
Now it is easy to pair each query to its reply.
Message numbers are 8 bits, autoincrement, and wrap around from 0xFF -> 0
Message numbers are enabled by fControlMessageNumsEnabled, or by the first occurrence of an M.
M without data will clear the message number.
S407D M05 R01 M R01 R01
057D[eol]007D[eol]017D[eol]
As well as I2C bus, the pins can be used directly, or to write to many SPI devices. Contact us before making use of these features, as they are being completely revised
You can read and write the pins directly. The 'O' output command can be used to write to the output pins, and the data direction registers. The bit number of each pins is given in 2 Table 1: BL232 Pinout Description.
Expects sequence of O Data0-7, Data8-15, TRIS0-7, TRIS8-15, Data0-7...
You can write 1 or more bytes in this sequence
O 0F F0
[write][Data=0FF0][tristate=0x00 ]
To read the pins, you first need to set the corresponding tristate register bits to '1'. Ensure that you
8 bit bytes are written using SCL and SDA. The bus must be in STOP before using SPI write. The SPI strobe or CS pin function is done using direct I/O above.
P Y 01 02 03
[I2C Stop][SPI write 0x01,0x02,0x03][CS low]
The 128 Bytes of EEProm contains:
Address |
Description |
|
0xF8 |
fSerial |
RS232 Control Register |
0xF9 |
Baud_Div |
Baud rate divisor |
0xFA |
TimerDivL |
Low byte of timer divisor (TimerDiv) |
0xFB |
TimerDivH |
Hi byte of timer divisor |
0xFC |
fControl |
Control Register |
0xFE |
IRQ1Vector |
Macro address for interrupt |
0xFF |
Watchdog Vector |
Macro address for |
0 |
Base / POR |
First macro instruction. Power-On jumps to this location. |
0x87 |
end |
Generally contains a return char ">" |
Macros are stored command chars.
This board uses (you guessed it) an 8574. The 8574 is a open-drain driver. We can connect switches across the drivers, and read the switches if we momentarily turn the LEDs off (write 1's)
S40FF R01 W <
[write 0xFF to turn leds off][read 1 byte][start write][return] we now expect the LED data to follow.
To use the macro:
>20 00 P
[goto macro][new led data][stop]
This is a simple data-logging application. It reads the 4 A-D channels of a PCF8591, and 8 switches with an 8574, 4 times a second, and streams the data to a PC, that captures it with a terminal program.
start location is 0x10
S9104 S4101 P D00F9 ; >10
[read 4 a-d][read 8574][delay 249ms][return if the PC sends a char][jump to start]
To prevent inadvertent writes to the EEProm, each byte( both address and data) is sent twice. First normally, then inverted. If they don't match, the whole operation is aborted.
The format is V[address][not addr][byte1][not byte1]…..
Address 0 is the Base / POR location. So to write F1,01,11 to the POR location:
V00FF F10E 01FE 11EE
Each byte written takes 10ms. You need to either send data slowly enough, or in small packets eg 8 locations to avoid overflowing the buffer.
The EEProm write command is intended for configuration, rather than routine use.
If fSerialEEWriteProtect is set, further writes to EEProm are blocked unless in Special Pins Mode
U will dump all 128 bytes of EEProm in the order shown in the Table 3: EEProm Memory Map. ie the first byte is fSerial, not Base/POR
Both the EOL char and the separator char can be set in EEProm. They can be changed to get a different data format that is easier to use.
EOL (LF 0x0A by default) is sent back to separate commands.
The separator char is not used by default but may be set to any value that suits the particular program interpreting the data. Eg comma, space, or tab. This will add 50% comms overhead of course.
e.g. Change separator to TAB, and EOL to CR, to make Excel readable files
Data format cannot be changed.
The baud rate is set by writing the ee_BaudDiv and ee_fSerial locations in EEProm. The changes will become active when the part is next reset.
As you can cock the baud rate up, and be left with an unusable chip, we have provided a special mode where the baud rate and fSerial are in their factory state. To enter SPM, force Pins 1,2,17,18,6 to 0, during and 500ms after reset / power on. Now you can change the EE.
The BL232 can have baud rates as high as 921kbd. However it cannot process commands at this rate. Different commands take differing amounts of time to execute, and so you should experiment to find the optimal rate for your application. It is likely to have an appropriate throughput for 115kbd.
Where speed is an issue, make use of macros stored in EE to reduce the serial traffic.
While Windows PC's, USB devices, and anything running over the internet, have high data throughput (bytes per second), they have long latencies or transit times.
On a Windows PC that can send 10,000 bytes/sec, it may take as long as 300ms for a single char to loop back.
At high baud rates (20k +) you need to pay attention to the RS232 Drivers. Driver IC's vary in their ability to drive longer cables at high speed. Variants, eg xxxE parts can have different speeds. Different manufacturers versions of the same part have different speeds. Also beware that at the PC end, some serial ports eg older laptops, may use low power drivers that are rated to 20k.
It is best to keep command strings within the buffer. When reading a port, avoid reading more chars than will fit in the buffer.
RTS/CTS hardware handshaking is supported. It is controlled by bit fSerial_UseRTS. XON/XOFF handshaking is not supported.
bit 7 |
bit 6 |
bit5 |
bit4 |
bit 3 |
bit 2 |
bit 1 |
bit 0 |
||
fSerial |
EEWrProt. |
UseXon |
UseRTS |
Baud Rate HI |
|||||
BaudDiv |
Baud Rate Divisor |
||||||||
The usb has a drawback. Data is passed in 1ms frames. This means that there is a minimum 1ms turnaround for even a single char. Structure your data so that you send as many commands as possible before your program requires a response.
The standard oscillator frequency is 14.7456MHz. This permits standard baud rates as high as 921kbd.
As the BL232 is much faster than many applications will require, you can change the crystal for a lower frequency. This will allow operation at lower voltages, lower supply current, and reduced EMI.
Both BaudDivisor and TimerDivisor can be set in EEProm.
The max oscillator frequency is 20MHz. The I2C Bus timing is set for Standard Mode at 14.74MHz
The timer ticks run at 1ms with a 14.7456MHz crystal. You can change the timer rate using the 16 bit EEProm register TimerDiv.
The chip has a watchdog function that is used to monitor correct functioning of the host computer. A typical use might be to force a hardware reset of the host PC.
The watchdog period is fixed at ????.
Each time a character is received from the host, the watchdog is restarted. After NNNN ticks without a character received, a watchdog event can be generated.
If the watchdog vector is not 0, then exception jumps immediately to the watchdog subroutine. The current character will be processed, then the next char is fetched from the watchdog location.
You need to bear in mind that bus transactions may be left half completed.
not implemented
Z will put the part to sleep. It will wake on pin change. This could be from an I2C interrupt, or by connecting the RTS or RXD pin to a pin change input.
You need to allow 10ms for wakeup from sleep.
If you are waking it with the RXD line you need to be aware of the potential for waking up part way through the char used to wake it. For this reason 0xFF is recommended as the wakeup char.
This 45x80 mm module can be used standalone in its enclosure, or as an OEM module in your equipment to provide a complete USB and RS232 interface with 3 I2C ports, and 1 buffered high current I2C.
Galvanic isolation can be installed where the I2C busses need to be isolated from the computer.
There is an internal 5V power supply to run the interface and target hardware. Building an I2C based instrument needs nothing more than your I2C chip, everything else is included.
An optional Fibre Optic interface is available where very high voltage or totally secure isolation is required.
An RS422 interface is available for long distance or high noise immunity.
Ferrite beads are fitted to all data lines for EMC protection.
Figure 2
The I2C Bus can be isolated in two ways.
The easiest is to isolate the serial data stream.
A single PCF8574 can drive a standard LCD module. This circuit is available built up.
To get are large number of cheap and easy output pins with good drive capability, use the SPI output, and 74HC4094 shift registers. Eg a 32 bit output with 4x 4094's. SDA4 is used as STB for the 4094's
G3 Y01020408 OFFFD OFFFC
[select bus3][send 4 bytes to 4094's][pulse STB pin to latch data] nb O not zero
DIP parts are available in low volume. SSOP20 parts are only available for volume orders at this time.
DIP18: BEL232-P
SSOP20: BEL232-M
EEProm settings can be customised at the factory.
We offer all customers a link page on our web site, where others can find out about your products. We encourage you to use this.