Importing PIC code to AVR

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
waitsy
Posts: 3
Joined: Tue Feb 24, 2009 1:50 pm

Importing PIC code to AVR

Post by waitsy »

Hi There,

I have been experimenting with EBlocks system with a EB006 (PIC Board) and EB0019 (AVR Board) with reference to Bert van Dam's Elektor project book for flowcode. I have a query regards importing flowcode to another microcontroller(as per chapter 10 page 288-290).

I followed the simple stairway light timer project (chapter 2 page 17-32), this worked for both PIC16f88 and f877 and also imported onto the AVR as described in the book and ran as expected.

I went onto recreate the CAN bus project (chapter 7 page 232-239), with AVR transmitting to PIC and again this worked fine. I then developed this project so that the PIC node was able to transmit and receive on different msg ID's with an LCD atached at each end to show tx/rx status (see attached code, CAN txrx.fcf). This ran ok data could be received by the PIC as in example and could also be transmitted to AVR (scoped on CANH, CANL terminals), however AVR couldnt read it as not setup yet. Therefore I attempted to import the PIC tx/rx code into the AVR, setting up INT & CS to B3 & B4 in general settings as recommended in the book, which compiled and programmed ok. When running I could transmit from AVR to PIC as in the original example, but when receiving data the AVR device and CAN Controller crashed needing a hardware reset.

After spending some time attempting to rectify this, I eventually re-drew the AVR txrx code by expanding on the original AVR tx as in the original book example. When programmed and run this now worked ok, being able to transmit and receive the CAN controller switches from each node (see attached code CAN avr txrx.fcf_avr). Looking at both versions side by side they are practically the same ( disregarding a few LCD and unused PORT D outputs). So I suspect this problem is caused by the need to change from PORT C to PORT B for the AVR SP1 connections?

As a further test I created a simple project using the CAN Controller to show a CAN switch press on the CAN led's ( see attached code CAN swled.fcf). This worked ok on the PIC but not when imported to AVR ( again after setting up INT & CS to B3 & B4 in general settings). Once again re-drawing this for the AVR and it works fine.

I dont know whether im missing something obvious here or if it is a bug that you need to be aware of. Im assuming that there supposed to be a requirement to change the CAN bus from PortC to Port B in flowcode (for the PIC to AVR), as this appears to be setup within the macro functions.

Thankyou
Attachments
CAN swled.fcf
CAN switch leds test
(7 KiB) Downloaded 264 times
CAN avr txrx.fcf_avr
CAN Transmit/Receive for AVR
(8 KiB) Downloaded 271 times
CAN txrx.fcf
CAN Transmit/Receive for PIC
(10 KiB) Downloaded 269 times

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: Importing PIC code to AVR

Post by Sean »

Unfortunately there is an unavoidable requirement to reallocate ports and pins when retargetting some programs from one device to another. Flowcode components that use hardware peripheral functions will be automatically allocated the ports and pins appropriate for the target device. Other components, that do not have specific hardware requirements, will retain the allocations made in the original program.

In the case of the 'CAN avr txrx' program, the movement of the CAN function from Port C (PIC) to Port B (AVR), caused by the SPI hardware location, forces a clash between the CAN component and the LCD (also on Port B). Moving the LCD to another port should resolve this problem.

I don't have a copy of the book available tonight, but I should be able to obtain a copy tomorrow and will check the advice on importing/re-targetting programs.

Post Reply