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??!
$$\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}}$$