ATReady for XMEGA Board MikroPascal xMega Libray Support

General discussion on mikroPascal PRO for AVR.
Post Reply
Author
Message
DaveTesla
Posts: 7
Joined: 22 Apr 2010 03:23

ATReady for XMEGA Board MikroPascal xMega Libray Support

#1 Post by DaveTesla » 29 May 2013 01:49

Is there a list of Library routines that have been tested with the xmega128A1?

I am trying to use a CAN SPI click 3.3V board that I have attached to the Ready for XMEGA Boards.
Using the examples and two boards I can successfully compile the programs but don't get a SCLK
to the MCP2515 on either board.

Does the CANSPI LIBRARY work with an xMega?
The USB UART works as does my other code (I have removed for simplicity).
Here is the modified example i used for one board,

Code: Select all

program USB_CAN_Test_01;

var uart_rd : byte;
Rxchar1 : char;
TxChar1 : char;
Command1 : String[30];
Command2 : String[30];
Cmnd : integer;



var Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags : byte;   // can flags
    Rx_Data_Len : byte;                                     // received data length in bytes
    RxTx_Data   : array[8] of byte;                         // can rx/tx data buffer
    Msg_Rcvd : byte;                                        // reception flag
    Tx_ID, Rx_ID : longint;                                 // can rx and tx ID

// CANSPI module connections
var CanSpi_CS : sbit at PORTD_OUT.0;
    CanSpi_CS_Direction : sbit at PORTD_DIR.0;
    CanSpi_Rst : sbit at PORTD_OUT.2;
    CanSpi_Rst_Direction : sbit at PORTD_DIR.2;
// End CANSPI module connections


begin

  // Internal oscillator selection
  OSC_CTRL := 0x02; 

  while RC32MRDY_bit = 0 do nop;

  CPU_CCP := 0xD8;
  CLK_CTRL := 1; 

  PORTQ_DIRSET := 255;         // Set PORTQ as output
  Sound_Init(PORTQ_OUT, 2);    // Initialize the pin PQ2 for playing sound


  Sound_Play(1000, 500);   // Initilize / Start Beep

  UARTC0_Init(921600); 
  Delay_ms(100);
  UARTC0_Write_Text('Embedded Systems');
  UARTC0_Write(13);UARTC0_Write(10);



  Can_Init_Flags := 0;                                      //
  Can_Send_Flags := 0;                                      // clear flags
  Can_Rcv_Flags  := 0;                                      //

  Can_Send_Flags := _CANSPI_TX_PRIORITY_0 and               // form value to be used
                    _CANSPI_TX_XTD_FRAME and                //     with CANSPIWrite
                    _CANSPI_TX_NO_RTR_FRAME;

  Can_Init_Flags := _CANSPI_CONFIG_SAMPLE_THRICE and        // form value to be used
                    _CANSPI_CONFIG_PHSEG2_PRG_ON and        // with CANSPIInit
                    _CANSPI_CONFIG_XTD_MSG and
                    _CANSPI_CONFIG_DBL_BUFFER_ON and
                    _CANSPI_CONFIG_VALID_XTD_MSG;

  SPID_Init();                                                      // initialize SPI1 module

  CANSPIInitialize(1,3,3,3,1,Can_Init_Flags);                       // Initialize external CANSPI module
  CANSPISetOperationMode(_CANSPI_MODE_CONFIG,0xFF);                 // set CONFIGURATION mode
  CANSPISetMask(_CANSPI_MASK_B1,-1,_CANSPI_CONFIG_XTD_MSG);         // set all mask1 bits to ones
  CANSPISetMask(_CANSPI_MASK_B2,-1,_CANSPI_CONFIG_XTD_MSG);         // set all mask2 bits to ones
  CANSPISetFilter(_CANSPI_FILTER_B2_F4,3,_CANSPI_CONFIG_XTD_MSG);   // set id of filter B1_F1 to 3

  CANSPISetOperationMode(_CANSPI_MODE_NORMAL,0xFF);                 // set NORMAL mode

  Tx_ID := 12111;



              while (TRUE) do  // Endless loop
                Begin
                   RxTx_Data[0] := 2;
                   CANSPIWrite(Tx_ID, RxTx_Data, 1, Can_Send_Flags);
                   Msg_Rcvd := CANSPIRead(Rx_ID , RxTx_Data , Rx_Data_Len, Can_Rcv_Flags);

                     if ((Rx_ID = 3) and Msg_Rcvd) then
                       begin
                         Inc(RxTx_Data[0]);
                         Delay_ms(10);
                         CANSPIWrite(Tx_ID, RxTx_Data, 1, Can_Send_Flags);
                       end;
               end;
end.

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: ATReady for XMEGA Board MikroPascal xMega Libray Support

#2 Post by dejan.odabasic » 30 May 2013 10:47

Hello,

Depending on you MCU selection listed libraries in Library Manager are updated, only supported libraries/functions are listed.

Problem with missing SCK could be caused by wrong connections or by program freezing on some line before SPI communication with CAN chip.
I would suggest that you test unchanged example project for CAN SPI, which can be found in folder:
..\compiler\Examples\Extra Boards\Can Spi\

For CAN SPI click board I suggest using the following configuration:

Code: Select all

  // Focs = 10MHz, SJW = 1, PHSEG1 = 3, PHSEG2 = 3, PROPSEG = 1, -> N = 1+3+3+1, N = 8
  // Desired Baud rate Fbaud = 125kb/s
  // BRP = Fosc/(2*N*Fbaud) = 5
  CANSPIInitialize(1,5,3,3,1,Can_Init_Flags); 
If you like to use some other baud rate, you can try out CANculator application:
http://www.libstock.com/projects/view/360/canculator

Best regards.

DaveTesla
Posts: 7
Joined: 22 Apr 2010 03:23

Re: ATReady for XMEGA Board MikroPascal xMega Libray Support

#3 Post by DaveTesla » 31 May 2013 02:50

"Depending on you MCU selection listed libraries in Library Manager are updated, only supported libraries/functions are listed."

Very nice feature..
That is what I needed to know!

I didn't want to delve into troubleshooting if the library would not work in the first place.

The software is not hanging up so it is either a problem with the code or the wiring.

I will let you know what I find.

(p.s. Thanks for the quick response.)

Post Reply

Return to “mikroPascal PRO for AVR General”