|
|
View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
Undefined identifier -- i2c_speed |
Posted: Mon Apr 17, 2023 8:08 am |
|
|
The compiler is unable to link to i2c_speed() in my project.
P24FJ64GA002
PCD 5.114
This board acts as an I2C slave device from a PC host program, and then acts as an I2C master for sub-boards (a message multiplexer, basically). I was trying to add a new I2C message (internal protocol) to change the subnet bus speed for testing. Here is how we initialize the subnet:
Code: | #use i2c (MASTER, I2C1, FAST=400000, FORCE_HW, stream=SUBNET_BUS) |
This looks like it is using hardware to me, which matches the help file notes:
Quote: | This only works if the hardware I2C module is being used. |
I expect I am missing something obvious? _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
|
Posted: Mon Apr 17, 2023 10:46 am |
|
|
On another one of our boards, using 24FJ256GA106, i2c_speed() is in use and links in fine. Both projects look like they initialize the same way:
Code: | #use i2c (MASTER, I2C1, FAST=1000000, FORCE_HW, stream=RF_BUS)
#use i2c (MASTER, I2C2, FAST=400000, FORCE_HW, stream=INTERNAL_BUS)
|
_________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19477
|
|
Posted: Wed Apr 19, 2023 9:54 am |
|
|
You don't need 'FORCE_HW', setting the port name (I2C1), automatically
forces the hardware port to be used.
Your chip has the i2c peripheral, not the MSSP. On this speed has to be
changed with i2c_init, not i2c_speed.
i2c_init(SUBNET_BUS, 100000);
etc.. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
|
Posted: Wed Apr 19, 2023 8:39 pm |
|
|
Ttelmah wrote: | You don't need 'FORCE_HW', setting the port name (I2C1), automatically
forces the hardware port to be used.
Your chip has the i2c peripheral, not the MSSP. On this speed has to be
changed with i2c_init, not i2c_speed.
i2c_init(SUBNET_BUS, 100000);
etc.. |
Good note on FORCE_HW. I was unaware of that. I think I am the one that added it in, when I read about things that didn't work with software.
What is MSSP? I searched the data sheet for the 24FJ256GA106 (the one where i2c_speed() exists) and did not get a hit.
The other, 24FJ64GA002, will be just fine using i2c_init() again. Wouldn't they do about the same thing, unless i2c_speed() hits less registers, I suppose? _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 471 Location: Montenegro
|
|
Posted: Thu Apr 20, 2023 12:14 am |
|
|
Quote: |
The Master Synchronous Serial Port (MSSP)
module is the enhanced Synchronous Serial Port
developed by Microchip Technology and is featured on
many of the PICmicro devices. This module provides
for both the 4-mode SPI communications, as well as
Master and Slave I2C communications, in hardware. |
This is from some app-note from Microchip. Your chip seems to have separate modules for I2C and SPI. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19477
|
|
Posted: Thu Apr 20, 2023 1:27 am |
|
|
Historically, the MSSP, was the multi-function synchronous serial port.
Could be programmed to do SPI, or I2C.
Then on some of the PIC24/30/33's, Microchip separated the peripherals,
and gave an SPI peripheral, and a separate I2C peripheral. These function
somewhat differently to the MSSP. There are actually two different versions
of the I2C peripheral as well!.
Problem is that CCS 'hides' lots of things, so (for example), you have
#USE I2C, and don't have to worry which type of hardware you actually
have, but then differences do appear when you want to do things like
change speed. Hence, despite the 'hiding', you still need to be aware of
which peripheral you do actually have.
On the more sophisticated I2C peripheral, you cannot actually 'do' I2C_read
and I2C_write, having to use the automatic block transfer, since this does
not support single byte operation at all. Yours is the intermediate one that
does still allow read/write, but still has different registers for the baud rate
control. I2C_speed is not supported on this.
Key always is the .h file for each processor. On the ones with this peripheral,
you will not find I2C_speed listed. On the ones with the block only
peripheral, you won't find I2C_read or I2C_write. This file is an essential
'first call' when programming PIC's, especially when moving stuff between
different chips. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
|
Posted: Thu Apr 20, 2023 8:58 am |
|
|
Great information as always! Than you.
Alas, I cannot use i2c_init() with a variable, it seems:
Code: | i2c_init (SUBNET_BUS, baud); |
*** Error 27 "myfile.c" Line 430(35,39): Expression must evaluate to a constant ::
I already do some register bit stuff for my I2C routines (to detect a stop bit and know when the master has completed a transmission), so I expect there's a way for me to set the baud rate in there somewhere. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
|
Posted: Thu Apr 20, 2023 9:00 am |
|
|
Well that ended quickly... The datasheet says:
Quote: | The I2C module supports these features:
...
• Both 100 kHz and 400 kHz bus specifications |
If that's the case for 24FJ64GA002, then my routine gets simpler. Slow or Fast _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
|
Posted: Thu Apr 20, 2023 9:16 am |
|
|
Testing #use I2C with faster speeds works -- 500 shows that speed in my Saleae logic analyzer capture.
Setting to 1000000 caused the board to lock, being restarted by the watchdog timer.
(Testing at 500, 600, 700, 800 and 900 "worked" but retesting 1000Khz had that issue. I guess we stick with the slow FAST speed.)
#TheMoreYouKnow _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9215 Location: Greensville,Ontario
|
|
Posted: Thu Apr 20, 2023 10:00 am |
|
|
Really you actually believe what ChatGPT says??
As for speed...possible hardware issue (board clean, correct pullups,etc.), for software...possible bugs (wrong speed setting in registers , ??) |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
|
Posted: Thu Apr 20, 2023 10:06 am |
|
|
temtronic wrote: | really you actually believe what ChatGPT says??
as for speed...possible hardware issue ( board clean, correct pullups,etc.), for software...possible bugs( wrong speed setting in registers , ??) |
Could certainly be. We’ve ran in to a number of compiler bugs over the last few years, though they’ve fixed each one of them after we reported them.
I’ve had fun having ChatGPT help write scripts for processing GPS/EXIF data in my digital camera photos. One time I fed it some source, and noticed it added to the version history comments (!). Then later I fed it one, and it removed my name and changed it to “chatgpt” ;-) because I asked it to make something new based on mine. Heh. (https://github.com/allenhuffman/EXIFPhotoScripts) _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19477
|
|
Posted: Fri Apr 21, 2023 1:49 am |
|
|
On I2C, above 400KHz, you are running 'fast mode plus'. On this, _active
pull-ups are normally required_. It depends on the bus capacitance,
but unless the capacitance is very low, you are unlikely to meet the rise
time requirements, without either using current sources or a genuine
active pull-up.
Look at the LTC4311, which is a typical pull-up device for such a bus.
If the bus is short and low capacitance, you may well be able to get away
by just dropping the pull-up resistors. The key point about devices
supporting these higher speeds, is that they have higher gate output
drive currents, which allow stronger pull-ups to be used (and improve the
pull-down speed).
Also look at 'rise time accelerators', which is another term for the active
pull-ups. These have switched FET's to actually reduce the rise time, while
not drawing more current once the line is stable high or low. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 540 Location: Des Moines, Iowa, USA
|
|
Posted: Fri Apr 21, 2023 11:58 am |
|
|
Ttelmah wrote: | On I2C, above 400KHz, you are running 'fast mode plus'. On this, _active
pull-ups are normally required_. It depends on the bus capacitance,
but unless the capacitance is very low, you are unlikely to meet the rise
time requirements, without either using current sources or a genuine
active pull-up.
Look at the LTC4311, which is a typical pull-up device for such a bus.
If the bus is short and low capacitance, you may well be able to get away
by just dropping the pull-up resistors. The key point about devices
supporting these higher speeds, is that they have higher gate output
drive currents, which allow stronger pull-ups to be used (and improve the
pull-down speed).
Also look at 'rise time accelerators', which is another term for the active
pull-ups. These have switched FET's to actually reduce the rise time, while
not drawing more current once the line is stable high or low. |
Our main bus (Windows via FTDI chipset to our main boards) was designed to run at 1 kHz.
A few years back, when the board count went from three to 27, there were communication problems and errors. The bus was slowed down trying to help, but it never did. One of the tasks I did was to rewrite the firmware I2C code and then we could do 16 million messages with 0 errors. I recently ramped the main bus speed back to 1 kHz and it ran all weekend with zero errors.
That's what let me to wanting to speed up the sub bus (main bus talks to two boards, then up to four multiplexer boards which each can talk to 8 more devices). Our largest system only uses three multiplexers and 22 sub devices, but it works well.
The data sheet lists 1 kHz as a supported speed, but I get a crashing board when I do that. I need to find time to make an isolated firmware load that is just a main() with some I2C init stuff and see if that still has the problem. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19477
|
|
Posted: Sat Apr 22, 2023 2:01 am |
|
|
3 to 27, implies a huge rise in bus capacitance.
What are your pull-ups?. Assume this is a 3.3v system?.
Tc and Tr are specified as 120nSec max for a 1MHz I2C bus. This
gives a Rp(max) of Tr/(0.8473*Cb). So for a bus capacitance of 200pF,
this gives 708R. Now with 27 devices, 200pF, is going to be close to the
minimum possible capacitance. So to have any hope of working you need
to either clock slower, or drop the pull-ups to perhaps 700R. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|