For chips that have multiple I2C and or SPI peripherals, how does one tell the GCB hardware routines to use the second I2C or SPI rather than the first.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Are you desiring to use SPI2 and/or I2C2 on what chip? This is very important.
Are you desiring to use SPI2 and/or I2C2 because you are already using SPI1 and/or I2C1 and you desire to use SPI1 and/or I2C1 at the same time as SPI1/I2C2?
Are you desiring to use SPI2 and/or I2C2 with interrupts? and/or use SPI1 and/or I2C1 with interrupts?
Some insights. The compiler support SPI1 [where the [1] refers to the first channel, we call that SPI typically], Hardware I2C and Hardware I2C2. I cannot think of an ask for support for SPI2. Most libraries support SPI1 and/or IC2C for hardware and of course software SPI and/or I2C.
But, the answers for the question are sort of critical. What is the goal?
As using software SPI and software I2C may be a better option.
Using PPS can typically resolve the complexity of I2C2 and SPI2
Using a few select #define(s) means you can use the I2C1 and the SPI1 with the second channel on non-PPS chips
So, simple answer is yes. But, more questions than answers. Sorry.
:-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
At the risk of confusing the issue, I will elaborate a little.
I want to use both an SPI piece of hardware, and an I2C piece of hardware. In this case, the SPI hardware is the 8 digit led I talked about in another thread, and the I2C is a standard 1602 lcd display. The lcd display is only for debugging purposes at this time.
My original question was more of a general question. What if I had two I2C pieces of hardware, or two SPI items. I just wanted to know how to handle such situations as I couldn't find any relevant documentation or demos. I couldn't find any way to refer to SPI2 or I2C2.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The are number I2C2 demos. Have a look at ..Demos\i2c_solutions\i2c2_discovery There is code I wrote totally by accident.
So, we have I2C and I2C2 support. We only have SPI not SPI2 support but this is not hard to add. If someone had a need it would be relatively easy to resolve.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The demos don't actually use the device, they just do discovery.
Here's a program that tries to actually connect to and print on an lcd display-
' test of I2C2
#optionExplicit
#chip16F18325,32'Generated by PIC PPS Tool for Great Cow Basic for 16F18325
#startupInitPPS, 85' new setup that doesn'tworkSubInitPPS'Module: MSSP2RC5PPS=0x001A'SCL2 > RC5SSP2CLKPPS=0x0015'RC5 > SCL2 (bi-directional)RC4PPS=0x001B'SDA2 > RC4SSP2DATPPS=0x0014'RC4 > SDA2 (bi-directional)EndSub
#include<lowlevel\hwi2c2.h>' Define Hardware settings for HWI2C2
#defineHI2C2_BAUD_RATE400' Define I2C settings
#defineHI2C2_DATAPORTC.4
#defineHI2C2_CLOCKPORTC.5DirHI2C2_DATAin'Initialise I2C MasterDirHI2C2_CLOCKin'I2C pins need to be input for SSP2 moduleHI2C2ModeMaster'MASTER Second Port
#defineLCD_IO10
#defineLCD_SPEEDFAST'FAST 'SLOWorMEDIUM' end new setup''Normalsetupthatworks'Sub InitPPS''Module: MSSP1' RC5PPS = 0x0018 'SCL1>RC5' SSP1CLKPPS = 0x0015 'RC5>SCL1(bi-directional)' RC4PPS = 0x0019 'SDA1>RC4' SSP1DATPPS = 0x0014 'RC4>SDA1(bi-directional)'End Sub''#define HI2C_BAUD_RATE 400'#define HI2C_DATA PORTC.4'#define HI2C_CLOCK PORTC.5'Dir HI2C_DATA in 'I2Cpinsneedtobeinput'Dir HI2C_CLOCK in'HI2CMode Master'#define LCD_IO 10'#define LCD_SPEED FAST 'FAST' SLOW or MEDIUM''endnormalsetupprint"lcd set up!!!"do:loop
The second block that is commented out is where I tested using the normal setup on the same pins to be sure the hardware was working.
The new code doesn't actually print to the lcd.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You are correct. The LCD I2C driver will need a little help to make it work as this is only supporting I2C not I2C2.
Just looked. This would require the INIT and the LCDNormalWriteByte routines to be updated - which would require some clever thinking. Why? The use cases are as follows, I am assuming hardware I2C and hardware I2C2
Only the constant HI2C_BAUD_RATE exists. LCD would work as it does today.
Only the constant HI2C2_BAUD_RATE exists, Adapting methods within the LCD.h could be adapted to do this and then the LCD could work.
Both HI2C_BAUD_RATE and HI2C2_BAUD_RATE constants exist. How do the methods determine which I2C interface to use? Using the constant method of HI2C_BAUD_RATE and HI2C2_BAUD_RATE would mean the both interfaces would be address with the same data stream.
So, to resolve use case. We could use #if-#endif to only run the code we require, we could add a constant LCD_I2C_DISABLED and LCD_I2C2_DISABLED then we could encapsulate the code as follows:
My first thought was to add a Print2 routine, so I could have two lcd displays connected and print to either one. But then, I don't know the complexities of GCB.
by the way, when I tried to run the i2c2 discovery demo I got the following error:
WARNINGs / ERRORs reported by Great Cow BASIC (if Syntax Error, doubleclick on the errormessage below) <<<
usart.h (484): Error: Incorrect parameters in Set, expected: Set variable.bit status
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Also, my needs are not nearly enough to justify a giant rewrite. I can work around my problems, so don't feel pressured to come up with a solution. Just maybe put it on your long term to do list.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Added. It is a low priority as you can use PPS to move I2C to other ports... the I2C and I know of few projects that would not use I2C for the LCD and I2C2 for something other device.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
it's the demo program with no changes.
\GreatCowBasic\Demos\i2c_solutions\i2c2_discovery\i2c2hardwarediscovery_to_terminal_alternative_display_16f18855.gcb
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For chips that have multiple I2C and or SPI peripherals, how does one tell the GCB hardware routines to use the second I2C or SPI rather than the first.
Nice question.
A few questions first.
Some insights. The compiler support SPI1 [where the [1] refers to the first channel, we call that SPI typically], Hardware I2C and Hardware I2C2. I cannot think of an ask for support for SPI2. Most libraries support SPI1 and/or IC2C for hardware and of course software SPI and/or I2C.
But, the answers for the question are sort of critical. What is the goal?
So, simple answer is yes. But, more questions than answers. Sorry.
:-)
I want to use both SPI and I2C at the same time.
I want to use the GCB hardware routines for performance reasons.
I understand that since I2C and SPI both use the resources of an MSSP module, one can't do both at the same time on the same MSSP.
So, I would need to use a chip with at least two MSSP modules. Thus I am starting with a 16F18325.
There is no current plans to use interrupts associated with either module.
These are the simple answers, I can elaborate on any you desire, but I didn't want to confuse the issue.
At the risk of confusing the issue, I will elaborate a little.
I want to use both an SPI piece of hardware, and an I2C piece of hardware. In this case, the SPI hardware is the 8 digit led I talked about in another thread, and the I2C is a standard 1602 lcd display. The lcd display is only for debugging purposes at this time.
My original question was more of a general question. What if I had two I2C pieces of hardware, or two SPI items. I just wanted to know how to handle such situations as I couldn't find any relevant documentation or demos. I couldn't find any way to refer to SPI2 or I2C2.
The are number I2C2 demos. Have a look at ..Demos\i2c_solutions\i2c2_discovery There is code I wrote totally by accident.
So, we have I2C and I2C2 support. We only have SPI not SPI2 support but this is not hard to add. If someone had a need it would be relatively easy to resolve.
The demos don't actually use the device, they just do discovery.
Here's a program that tries to actually connect to and print on an lcd display-
The second block that is commented out is where I tested using the normal setup on the same pins to be sure the hardware was working.
The new code doesn't actually print to the lcd.
You are correct. The LCD I2C driver will need a little help to make it work as this is only supporting I2C not I2C2.
Just looked. This would require the INIT and the LCDNormalWriteByte routines to be updated - which would require some clever thinking. Why? The use cases are as follows, I am assuming hardware I2C and hardware I2C2
So, to resolve use case. We could use #if-#endif to only run the code we require, we could add a constant LCD_I2C_DISABLED and LCD_I2C2_DISABLED then we could encapsulate the code as follows:
And, add a script as follows:
This approach would maintain backwards compatibility - which is so important in the libraries.
A bit of work but doable. The regression testing of the exists I2C is very important. Dont want to break anything.
These are my inights.
You're the expert, sleep on it :)
My first thought was to add a Print2 routine, so I could have two lcd displays connected and print to either one. But then, I don't know the complexities of GCB.
by the way, when I tried to run the i2c2 discovery demo I got the following error:
Post the code as an Attachment!
Last edit: Anobium 2019-11-16
Also, my needs are not nearly enough to justify a giant rewrite. I can work around my problems, so don't feel pressured to come up with a solution. Just maybe put it on your long term to do list.
Added. It is a low priority as you can use PPS to move I2C to other ports... the I2C and I know of few projects that would not use I2C for the LCD and I2C2 for something other device.
it's the demo program with no changes.
\GreatCowBasic\Demos\i2c_solutions\i2c2_discovery\i2c2hardwarediscovery_to_terminal_alternative_display_16f18855.gcb
Scratch that. I just tried it again, and everything is okay. Don't know what happened the first time.
okay. I managed to reproduce the error. I was farther along than I remembered when it happen.
The full program is attached. It is identical to the original except the chip and the pps section.
edit: remove attachment which was just copy of demo with different chip and pps.
Last edit: Jim giordano 2019-11-17
Remove #define sync SYNC_TX1STA
I will remove from all the demos. #define sync SYNC_TX1STA is a tie over from when the DAT file was broken. I have deleted from all the demos.