# How to take this variable out of this equation?

I'm working to develop a function in my embedded code for i2c initialization.

I came up to this equation which is to calculate the speed of the i2c clock.

But if I want to develop a function that takes a user popular numbers for speed then I have to change the shape of the equation to get that variable in place to receive users values for adjusting the speed.

This is the equation:

$$\mathrm{SCL\ frequency}=\frac{\mathrm{CPU\ Clock\ frequency}}{16+2\ \mathrm{TWBR}\ \cdot\ \mathrm{Prescaler\ Value}}$$

I want to take out TWBR instead of SCL frequency. I tried to do it on a paper but I don't know how to take it out, from the multiple PrescalerValue and the addition of 16??!

• Multiply both sides by the denominator, move the SCL term to the right member and divide by the coefficient of TWBR. – Yves Daoust Apr 19 at 9:24
• You may take reciprocals, multiply by CPU, subtract $16$ and finally divide by $2$PrescalerBValue. – Michael Hoppe Apr 19 at 9:30
• OK, thank you so much :) – Perch Eagle Apr 19 at 9:32
• @MichaelHoppe OK, thanks :) – Perch Eagle Apr 19 at 9:32
• Sorry guys didn't know how to do it! – Perch Eagle Apr 19 at 9:47

$$\mathrm{SCL\ frequency}=\frac{\mathrm{CPU\ Clock\ frequency}}{16+2\ \mathrm{TWBR}\ \cdot\ \mathrm{Prescaler\ Value}}$$

Multiply both sides by $$16+2\ \mathrm{TWBR}\ \cdot\ \mathrm{Prescaler\ Value}$$, and divide both sides by $$\mathrm{SCL\ frequency}$$:

$$16+2\ \mathrm{TWBR}\ \cdot\ \mathrm{Prescaler\ Value}=\frac{\mathrm{CPU\ Clock\ frequency}}{\mathrm{SCL\ frequency}}$$

Subtract $$16$$ from both sides:

$$2\ \mathrm{TWBR}\ \cdot\ \mathrm{Prescaler\ Value}=\frac{\mathrm{CPU\ Clock\ frequency}}{\mathrm{SCL\ frequency}}-16$$

Divide both sides by $$2\ \mathrm{Prescaler\ Value}$$:

$$\mathrm{TWBR}=\frac{\mathrm{CPU\ Clock\ frequency}}{2\ \mathrm{SCL\ frequency}\ \cdot\ \mathrm{Prescaler\ Value}}-\frac{8}{\mathrm{Prescaler\ Value}}$$

• Your answer is more better and arranged, thanks for the help :) – Perch Eagle Apr 20 at 8:51
• I removed my answer, thanks again. – Perch Eagle Apr 20 at 8:52