View previous topic :: View next topic |
Author |
Message |
xiaop@lsbu.ac.uk
Joined: 18 Apr 2018 Posts: 5
|
PIC16F1455 USB and I2C problems |
Posted: Tue Nov 13, 2018 4:34 am |
|
|
I am working with PIC16F1455, I have got both USB and I2C working separately, but not together, it boils down to one problem, clock:
For USB I have to set
#use delay(clock=48000000)
For I2C I have to set
#use delay(clock=8000000)
Is any solution for this? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Tue Nov 13, 2018 7:38 am |
|
|
Why on earth do you 'have to set' the clock to 8MHz for I2C....
You can set the I2C baud rate in it's setup.
It sounds as if possibly you are using the I2C without setting it's rate, which then means it defaults to 'as fast as possible', which would then give problems when you clock at 48MHz.
A typical I2C setup, would be:
#USE I2C (FAST=400000, I2C1, MASTER)
Using the hardware port at 400KHz.
I'm using this on a chip running at 120MHz.....
In your case, I think the chip only has software I2C, but the same applies. Just work out the rate that is working, and specify this when you switch to the higher CPU clock. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Tue Nov 13, 2018 7:58 am |
|
|
I was curious...watching snowflakes here.... that PIC does have HW I2C however the 'clock' has to be setup correctly. You should specify 'internal' if using the internal RC oscillator of the PIC.
Perhaps the version of your compiler defaults to it, but you should never assume it does what you think....
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Tue Nov 13, 2018 9:21 am |
|
|
Also, as a comment, just because you are using USB, you don't have to run the CPU at 48MHz.
The clock _feeding_ the USB needs to be at 48MHz, but the CPU can run at a division from this. So it can still run at 8, 16, or 24MHz if required.
If he is using the internal oscillator and USB, he needs ACT=USB in the clock setup, otherwise the clocking will not be accurate enough for reliability. |
|
|
|