Jump to content
  • 0

WaveForms I2C Custom Script Write Question.


wolfie

Question

Hello,
Can anyone tell me if the Write function (used in WaveForms I2C Custom Script) generates a stop bit?

Here is my script.

The first Write, writes a value to a register.
The 2nd Write is actually setting up for reading the register.  I need to know if this command is sending a stop bit or not.

// Simple test to read and write register using I2C
const adr = 0x64; // address of device
if(Clear()!=true) return "I2C bus error. Check the pull-ups.";
if(Write(adr)!=true) return "Device NAK";

Write(adr, 0x40, 0x00, 0xC0, 0x0E, 0x06); // Write the value 6 to register 0x4000C00E
Write(adr, 0x40, 0x00, 0xC0, 0x0E); // Send a write without data because we need to read this register

wait(0.1);

var rg = Read(adr, 1); // Read 1 byte from device

return rg;

This script appears to work, as rg ends up having the value 0X6.  But I need to know if a Stop bit is sent after that 2nd read.  If one is sent, this tells me my device under test will work with a Stop bit in between the write and the read.  I was told I need to read register on my DUT like this (notice no Stop bit in between the Write and the Read), which is why I'm asking:

Read:
| S | I2C ADDR R/W=0 | AS | REGADDR BYTE 4 | AS | REGADDR BYTE 3 | AS | REGADDR BYTE 2 | AS | REGADDR BYTE 1 | AS | S | I2C ADDR R/W=1 | AS | DATA BYTE 1 | AM | DATA BYTE 2 | AM | DATA BYTE 3 | AM |.. | DATA BYTE N | P |

Where:
S is the start bit
P is the stop bit
AM is acknowledge by master
AS is acknowledge by slave


Thanks!
Rob

Edited by wolfie
Copy and pasted wrong info
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hi @wolfie

Sure, stop is part of the I2C protocol. 
You can use the "Debug with Logic Analyzer" (in top-right corner) to inspect the signal timings.
You should use:
// Read(address, [sub address byte1, byte2...], count of bytes)
// Returns the read bytes array from the specified device address and subaddress using repeated start.
Read(addr, [regaddr 4, 3, 2, 1], N)

Edit: This will generate what you have described: start, addr write, sub-address bytes, repeated-start, addr read, N bytes, stop.

image.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...