Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bit banging I2C #20

Open
abbrev opened this issue Aug 27, 2020 · 4 comments
Open

Bit banging I2C #20

abbrev opened this issue Aug 27, 2020 · 4 comments

Comments

@abbrev
Copy link
Contributor

abbrev commented Aug 27, 2020

Hi @threeme3, is there a reason that I2C is bit banged on pins that support hardware I2C? Specifically in class I2C:

https://github.com/threeme3/QCX-SSB/blob/57e438da4425f3d22deb9ba9b5e64167a20d67b2/QCX-SSB.ino#L768-L775

We can probably at least reduce the code size a little by using the hardware I2C (though it probably wouldn't reduce the CPU load since we'd still have to synchronously wait for each byte to transfer).

@threeme3
Copy link
Owner

threeme3 commented Oct 7, 2020

Hi @abbrev,
Thanks for the suggestion on reducing the code size by using hardware I2C support.
Currently, the SSB TX implementation require a I2C bit-stream of about 750kbit/s, and a constant periodic point in time of submitting the new phase-frequency changes towards the si5351.
With hardware I2C support it is not easy to meet both criteria. This is unfortunate, because with hardware I2C support it would be possible to do some processing in the background while transporting I2C data, but on the other hand I2C hardware support would also generate +80k/s interrupts, which is also rather inefficient.

Thanks for raising this idea.
73, Guido

@threeme3 threeme3 closed this as completed Oct 7, 2020
@howard0su
Copy link
Contributor

I think it is not necessary to generate interrupts when using hardware I2C. We can still pull the reg which has the transfer finish flags. In such way, we don't save too much cpu time but rather reduce the size of the code only.

@threeme3 threeme3 reopened this Oct 8, 2020
@threeme3
Copy link
Owner

threeme3 commented Oct 8, 2020

Yes, this is a good idea, thanks Howard!
I have re-opened so we can think of a solution and test it out.

@howard0su
Copy link
Contributor

let's assume I2C runs on 800kbps, and the most common usage is SendPLLBRegisterBulk which changes Si5351 clock. The function issues the commands which contains 7 bytes + start + stop = 60 bits. It takes about 60/800k = 0.075ms = 75us. On 16Mhz AVR, it can run 1200 instructions. maybe worth to look at if we can combine freq_calc_fast with SendPLLBRegisterBulk and interleave the code to save some CPU load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants