![]() |
Forum Index : Microcontroller and PC projects : Low Level I2C commands on Picomite
Author | Message | ||||
vincenthimpe Regular Member ![]() Joined: 14/10/2018 Location: United StatesPosts: 63 |
Are there low-level i2c commands available ? like: I2CStart I2CRestart I2CSendbyte I2Cgetbyte I2cGiveACK I2CGetACK I2CStop I can bitbang it if needed but since the processor has i2c control registers. Alternately : is it possible to peek and poke the processor peripherals ? i could try rolling my own functions by talking directly to the i2c peripheral. |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7505 |
Will the commands detailed in the manual not do what you want? Appendix B has some examples. Talking directly to the peripheral could be awkward as the chip tends to be programmed in C, it's actually an internal module. . Edited 2025-05-07 04:38 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
vincenthimpe Regular Member ![]() Joined: 14/10/2018 Location: United StatesPosts: 63 |
hmmm. reading the rp2040 datasheet it looks like the i2 control cell cannot do what i am looking for . There is a bit available in the IC_data_cmd register to flag if a restart needs to be sent after the byte. But it looks like there are no specific flags to send just a START or STOP with actually transmitting a byte. I may have to wire up two additional GPIO pins in open collector mode and two as inputs to be able to issue and sniff "RAW" states on the bus. I want to be able to just issue a START and STOP without transmitting actual data or address to "block" the bus. Essentially preventing another master from talking. This would also allow me to perform "bus clear" to unstick an SDA line. or force clock-stretching Same thing goes for the restart condition. When turning around from writing to reading i don't want to release the bus. The I2C mechanism is to issue a restart at that point. Example : i need to read register 20 on device 10 (write address, 11 read address). normal operation : <Start>10<ACK>20<STOP><START>11<ACK><RESULT><STOP> The problem is between the stop and start the bus is free. At that point another master may claim the bus and alter what i just wrote into device @10. By changing the command to restart the bus is not released <Start>10<ACK>20<RESTART>11<ACK><RESULT><GIVEACK>.....<STOP> |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7505 |
The RP chips have no open drain mode. You have to simulate it by switching between input and output. It's a "feature". :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
vincenthimpe Regular Member ![]() Joined: 14/10/2018 Location: United StatesPosts: 63 |
Looks like the write command has the option to not generate a stop after the last byte. I2C WRITE addr,option, sendlen <-option =1 blocks the STOP So, to do a restart i can do: I2C Write 20,1,1,10 ' write without generating a stop I2C Read 20,0,1,result() ' reading (this generates a new START , which is essentially a restart ) i need to hook up a scope and see how it behaves. The read function also has the option to not generate a stop and keep claiming the bus. i would still use an extra GPIO on the SCL and data line to be able to clock stretch or clear a stuck bus. Looks like the RP2040 uses an i2c controller made by Synopsys . the IC_COMP_TYPE register contains the string "DW" which stands for "DesignWare". That's an IP library from Synopsys. I need to dive into its user manual. |
||||
vincenthimpe Regular Member ![]() Joined: 14/10/2018 Location: United StatesPosts: 63 |
I'Ll add two external mosfets. actually, reading the datasheet of the 2040 the output can be disabled. the GPIOx registers contain control bits. Bit 7 can disable the output driver. So it a can become an open drain Bit 6 controls the input Bits 5 and 4 allow the control of the drive strength ( 2,4,8 or 12 mA) Bit 3 controls the pull-up Bit 2 controls pull down (they are mutually exclusive though !) Bit 1 controls the schmitttrigger Bit 0 controls the slew rate MMbasic allows control over the pull up/down but not the drive strength or the other bits... i need to see if i can force this using a peek/poke Edited 2025-05-07 05:11 by vincenthimpe |
||||
PhenixRising Guru ![]() Joined: 07/11/2023 Location: United KingdomPosts: 1141 |
Hmmmm ![]() |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 4854 |
Vincent, Read the documentation in the manual, picpmite can issue the RESTART. It is an option yoy give to the write, to not release the bus, then do an i2c read. I use that often Ypu only need to generate a clock stretch when the pico needs it. And typically it does not. The pico can accept a slave that clock stretches, like an adc. To free the bus you generate 9 clock pulses. That must be done bypassing the i2c block. You are stuck when scl is stuck low. Then you can only free the bus by resetting peripherals, or the pico. Volhout Edited 2025-05-07 07:16 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
vincenthimpe Regular Member ![]() Joined: 14/10/2018 Location: United StatesPosts: 63 |
yes, found that option. Still need the ability to send a start and stop without transmitting address or data data (to lock the bus). I'll use two gpio pins driving two external mosfets tapped into the bus, so i can pull SDA and/or SCL low when i need. Same to be able to unlock the bus. Same to be able to create an arbitration lock. ( wait for the other master to release SDA and then JAM it low so he will fail arbitration on the next cycle and i can take over) I'm making an interactive tool to tap into a live system and play with register contents without requiring software on the computer side. Launch a terminal and you have a command prompt and can make "scripts". I don't need to develop an application on the computer side. (which is invariably a headache due to all the operating systems you have to support.) It's essentially an MMBasic library and you describe a device's register layout and can read/modify/write fields. I need a bit more capability than what the Pico's hardware can deliver. Some of the functionality is already in MMBasic , other is not since the hardware cell can't do it. The 2040 also has registers to program the duty cycle of the SDA and SCL lines ( hight time and low time) as well as noise rejection. I need to play with that ... Edited 2025-05-07 11:57 by vincenthimpe |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7505 |
Remember that some display types will lock the system clock speed. That might give you a restricted range if you start trying to tweak I2C frequencies and mark-space ratios. I'm even wondering if perhaps you should be using a SPI-I2C interface of some sort, letting the two systems run asynchronously. The I2C module on the RPi chips is just that - a relatively simple module without the full functions of a specialised device. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |