|
|
View previous topic :: View next topic |
Author |
Message |
rightbak
Joined: 16 Sep 2011 Posts: 10
|
PIC16F18325 and #pin_select |
Posted: Mon Jun 05, 2017 2:57 am |
|
|
MPLAB X IDE v3.40
CCS Version 5.070
PIC16F18325
I'm trying to write some code to bootload the device via RS232, but then once in the application, change those pins to use the I2C functions.
I can bootload the device fine over RS232, but then it fails to switch over to the new peripheral in the application.
A cut down bootload.c that I am using follows:
Code: |
#include "16F18325.h"
#fuses RSTOSC_HFINTRC,WDT,NOPUT,NOPROTECT,NOBROWNOUT,NOPPS1WAY
#use delay(clock=2000000, restart_wdt)
#pin_select U1TX = PIN_C0
#pin_select U1RX = PIN_C1
#use rs232(BAUD=9600,XMIT=PIN_C0,RCV=PIN_C1,ERRORS,STREAM=BOOT)
#define _bootloader
#include "bootloader.h"
#include "loader.c"
#if defined(__PCM__)
#org LOADER_END+1,LOADER_END+2
#elif defined(__PCH__)
#org LOADER_END+2,LOADER_END+4
#endif
void application(void)
{
while(TRUE);
}
void main(void)
{
// Read Bootload eeprom location and go into Bootload if its not set to 0x55
if(read_eeprom(BOOTLOAD_BYTE) != 0x55)
{
// Bootload the PIC
load_program();
}
// Now run application
application();
}
|
Now a snippet of the application code
Code: |
#include <16F18325.h>
#include "bootloader.h"
#fuses RSTOSC_HFINTRC,WDT,NOPUT,NOPROTECT,NOBROWNOUT,NOPPS1WAY
// Set clock speed
#use delay(clock=2M)
// Set up the Peripheral Select pins
#pin_select SCL1OUT = PIN_C0
#pin_select SCL1IN = PIN_C0
#pin_select SDA1OUT = PIN_C1
#pin_select SDA1IN = PIN_C1
#use i2c(Slave,I2C1)
.....
|
I've tried various other combinations over the past couple of days to try to get this to work i.e. trying the pin_select() function instead etc but have so far failed to make further progress. Any pointers would be much appreciated - thanks! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Mon Jun 05, 2017 5:37 am |
|
|
I haven't used any of the 'pin selectable' PICs but my gut feeling is that pin selects would be similar to fuses, only allowed to be 'set' once ??
Kinda makes sense to me....else chaos could happen !
I'm sure someone does know.... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Mon Jun 05, 2017 6:49 am |
|
|
That's what 'PPS1WAY' controls.
If this is set the PPS registers are 'one way'. Otherwise they can be re-configured. He has got them configured to be re-settable. The registers are protected from accidental updates, requiring an unlock sequence to access.
However there are configuration issues. I really would have the clock as INTERNAL=2MHz for both the bootloader and the code. Otherwise I'm not confident the compiler will be correctly configuring this.
It should work. However there seems to be a config problem with the chip. It's giving a warning, not an error:
"Option may be wrong Address is reserved". This is because a slave device _must_ have an address.....
Just tested with an address, and it works.
No complaints about the PPS. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 05, 2017 10:23 am |
|
|
Quote: | #include "16F18325.h"
#fuses RSTOSC_HFINTRC,WDT,NOPUT,NOPROTECT,NOBROWNOUT,NOPPS1WAY |
You have Watchdog timer enabled in the #fuses in both programs. Based
on the PIC datasheet, it will cause a reset every 2 seconds. Why are you
doing this ? You especially don't need WDT resets during development. |
|
|
rightbak
Joined: 16 Sep 2011 Posts: 10
|
|
Posted: Tue Jun 06, 2017 2:37 am |
|
|
I've made the following change to the WDT as suggested
Code: |
#fuses RSTOSC_HFINTRC,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOPPS1WAY
#use delay(clock=2000000, restart_wdt)
|
I was previously finding the bootloader would periodically 'pause' during the bootload process, but didn't link this to the WDT resetting! Turning off the WDT has fixed this issue. This is fine for now but I will turn WDT back on after development is complete and periodically kick the WDT to stop it resetting.
I have also changed the I2C use setting to the following
Code: | #use i2c(Slave,I2C1,ADDRESS=0x01)
|
Making this change has fixed the I2C problem! Many thanks for all the help |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Tue Jun 06, 2017 3:26 am |
|
|
Address 1, is not a legal I2C address. Beware.
On I2C, (in 8 bit nomenclature), the following addresses are reserved:
0, to 15 & 254/255. So 0x00 to 0x0F, and 0xFE/0FF.
112 legal addresses. |
|
|
rightbak
Joined: 16 Sep 2011 Posts: 10
|
|
Posted: Wed Jun 07, 2017 2:27 am |
|
|
Thanks for the warning - I've now moved the I2C Address away from one of the reserved ones. All seems to be working fine. |
|
|
|
|
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
|