Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Serial Interface on pic18f2550
23-08-2014, 11:12 PM,
#1
Serial Interface on pic18f2550
Hellow,

After quit a few attempts to read from the serial port of my pic18f2550 I've come to the conclusions that no matter what baud rate I use, my timings are always off.

As a result everything I sent or recieve trough the serial port is gibberish.
I was wondering what would cause this.

I must admit that my pinguino's are based on the setup of an xbox nand reader. You can find more about this reader over here: http://dev360.wikia.com/wiki/USB_Nand_SPI_Flasher

Now there are 3 major differences in my setup:
- I've used a crystal 12mhz! I've adapted the bootloader in winpic but I don't know if that's enough...
- I've setup Low Power so it was possible to program the pic with an art2003. This is also done in the nand reader of the xbox. I believe this was done by pulling down pin 26...
- I've used 33pf caps instead of 22pf caps.

I've also changed my PIC with another one to see if this worked but with little success. Also I'm trying to read/write to tx and rx with a raspberry pi.
Could this be a problem?

Before I order new parts or do something I could really use a professional opinion.

Ps: I think this issue is related to another post of my where I couldn't get a bluetooth device running. Now I realize it's not the bluetooth device that's causing the problems: http://forum.pinguino.cc/showthread.php?tid=4290

Regards

Xump
Reply
24-08-2014, 09:48 AM,
#2
RE: Serial Interface on pic18f2550
(23-08-2014, 11:12 PM)Xumpino Wrote: After quit a few attempts to read from the serial port of my pic18f2550 I've come to the conclusions that no matter what baud rate I use, my timings are always off.

As a result everything I sent or recieve trough the serial port is gibberish.
I was wondering what would cause this.

Check if your design is using USB. PIC18F2550 requires using the primary oscillator wth PLL for USB operation. If the core and peripherals share the primary clock, the serial port output will not be clean and won't communicate. If you try serial communication without using USB/PLL, it should work perfectly.

I suggest you setting secondary clock source for the core and peripherals.

Also this web page may be of help to you. http://www.edaboard.com/thread211205.html

DJ
Reply
24-08-2014, 12:23 PM,
#3
RE: Serial Interface on pic18f2550
(24-08-2014, 09:48 AM)djpark Wrote: Check if your design is using USB. PIC18F2550 requires using the primary oscillator wth PLL for USB operation. If the core and peripherals share the primary clock, the serial port output will not be clean and won't communicate. If you try serial communication without using USB/PLL, it should work perfectly.

I suggest you setting secondary clock source for the core and peripherals.

Also this web page may be of help to you. http://www.edaboard.com/thread211205.html

DJ

I think I most add that I'm using the pinguino framework. So I'm not sure about my design using USB.
I'm using USB to upload program's but afterwards my program only contains code from the pinguino framework.

Code:
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.print("A");
}

The design is based on the link I posted from the USB Nand Reader.
I wonder if I also need to set the correct clock (12Mhz) inside the Pinguino IDE or something like that.

USB is very stable and the upload of programs is no problem. Blinking leds is also no problems so the GPIO's are working perfectly.

Thanks,

Regards

Xump
Reply
24-08-2014, 08:00 PM,
#4
RE: Serial Interface on pic18f2550
From the link you provided, I was under impression that you are not using the Pinguino IDE.

I didn't look at the Pinguino serial code for PIC18. But check the serial library code and see if the serial init is based on core speed of 48MHz. Using different core speed will give different baud rate.

DJ
Reply
24-08-2014, 08:43 PM,
#5
RE: Serial Interface on pic18f2550
(24-08-2014, 08:00 PM)djpark Wrote: From the link you provided, I was under impression that you are not using the Pinguino IDE.

I didn't look at the Pinguino serial code for PIC18. But check the serial library code and see if the serial init is based on core speed of 48MHz. Using different core speed will give different baud rate.

DJ

Hey,

Yes I know it's a little confusion. That's because the design that I would normally use isn't using Low Power so can't be programmed with an art2003.
http://wiki.pinguino.cc/index.php/PIC18F2550_Pinguino

So I mixed them. I'm going to look into the init of serial. I suppose it isn't as simple as multiplying the baud rate times 4. (12Mhz against 48??). Sorry if that's a stuppid question. I'm no electronics engineer Wink

Thanks,

Regards

Xump
Reply
25-08-2014, 06:55 AM,
#6
RE: Serial Interface on pic18f2550
Though USB is not used by your app, USB is used for the bootloader and I expect the USB clock is set to 48MHz and core clock may also be 48MHz, but it can be different depending on CONFIG1.CPUDIV value.

Get the value of System_getCpuFrequency() to determine the core clock speed. Also read CONFIG1 to confirm if the result of this value is correct with your setup.

DJ
Reply
25-08-2014, 08:33 AM,
#7
RE: Serial Interface on pic18f2550
Ok I'm confused. According to the schematics here: http://wiki.pinguino.cc/index.php/PIC18F2550_Pinguino the clock is default set to 20Mhz for the pic18f2550. Where do you get 48Mhz??

I know you just need a multiplier of 4. So I've always used 12Mhz on the clock. I have enough of those crystals lying around.

I wrote the default pinguino bootloader (http://www.hackinglab.org/pinguino/downl...0V2-12.hex) and changed the divider in winpic to 3 so I would get 12Mhz on the clock. I've also changed the bootloader to use LP (Low Power) so I could write it with my art2003. Everything I've changed of the bootloader I have done in WinPIC!

For the rest I'm just using the Pinguino IDE to program the pinguino over USB.

So I don't really understand where to find those values CONFIG1.CPUDIV and System_getCpuFrequency().
The same for that file CONFIG1.

Thanks for the help,

Regards

Xump
Reply
25-08-2014, 09:32 AM,
#8
RE: Serial Interface on pic18f2550
USB on PIC18F2550 requires accurate clock of 48MHz to function properly. Primary clock source is divided by PLLDIV (PLL prescaler 1,2,3,4,5,6,10,12) to get 4Mhz, then converted to 96MHz by PLL. It is divided by 2 to get 48MHz clock for full speed USB (6MHz for low speed).

When PLL is used, the PIC core and peripherals can use this primary 96MHz divided by CPUDIV (PLL postscaler 2,3,4,6) to get 48, 32, 24 or 16Mhz. While primary clock is used for USB, the core and peripheral clock can also be supplied by external clock (T1) or internal RC clock (8MHz) divided by INTOSC postscaler.

If PLL is not used, the primary clock is divided by CPUDIV (oscillator postscaler 1,2,3,4) to be used for core and peripheral clock. The selection of these clock speed and source is controlled by FOSC.

Since USB bootloader is used, I presume the Pinguino reference model works this way by bootloader.

Primary crystal 20Mhz / 5 (PLLDIV=100) = 4Mhz
4Mhz * 24 (PLL) = 96Mhz PLL
96MHz / 2 = 48MHz USB clock
96MHz / 2 (CPUDIV=00) = 48MHz core & peripheral clock

This clock 48MHz is used for serial baud rate generation.

If you are using 12MHz crystal, PLLDIV=010 is used to divide it by 3 to get 4MHz input to PLL. The core/peripheral clock can be any of 48, 32, 24 or 16MHz depending on CPUDIV.

Once the clock speed is acquired correctly by System_getCpuFrequency(), the baud rate generation is configured correctly in serial.c. The System_getCpuFrequency() in oscillator.c seems having some room for improvement. For example, it assumes T1 is using 32KHz crystal, crystal for non-PLL is 8Mhz, internal RC oscillator speed will be reported as PLL speed. However, none of these conditions is happening with the bootloader.

If you can access the PLLDIV to change, you can also get the value of CPUDIV and FOSC from the hex file. Or you can refer to oscillator.c to get example of reading the values at runtime. Then check if these configuration and your hardware match and also match the the CPU frequency from the Pinguino library. The information on the configuration bits are well documented in the datasheet.

DJ
Reply
25-08-2014, 12:02 PM,
#9
RE: Serial Interface on pic18f2550
Woow, that's one hell of an explanation. Thanks man!

I think I can access the CPUDIV and FOSC the same way I changed my PLLDIV. I just need to look them up in WinPIC. Although I've never changed them. I only changed the PLLDIV from the original Bootloader... Maybe that's already some useful info.

For the moment I'm at work, when I'm home I'll check those values in WinPIC and I'll keep you posted.

Thanks again,

Regards

Xump
Reply
25-08-2014, 10:31 PM, (This post was last modified: 25-08-2014, 10:33 PM by Xumpino.)
#10
RE: Serial Interface on pic18f2550
Hellow,

Ok here I have a screenshot of my settings in WinPIC
http://picpaste.com/pics/PinguinoSetting...998785.JPG

Now I've noticed something interesting. When I pull out my tx cable on the (custom build) pinguino board and reatach it, the signal changes.
If I do this 3 times I get lucky and get a good signal response.

It's not the board or the cable because the pattern is to consistent. First time my screen returns all blank characters. Second time it returns �. And the third time it returns all A's. (I'm still using the same program as a posted previously)

I'm really starting to think that it has something to do with the connection to my raspberry pi.

You can just connect them end to end can you? Or do you need to add some resistors between the pinguino and raspberry pi? I've seen some people do this with an arduino. https://pbs.twimg.com/media/A7g86KCCQAAgwds.jpg

Any help is greatly appreciated.

Regards

Xump
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)