CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Error in setup_uart
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rfjhh



Joined: 31 Mar 2011
Posts: 51
Location: Mexico

View user's profile Send private message

Error in setup_uart
PostPosted: Fri Aug 16, 2019 10:24 am     Reply with quote

I'm beginning with dsPICs and I wrote a program using rs232 communication, but in the setup_uart(TRUE) an error is displayed:
Quote:

*** Error 102 "Prueba_CCS_01_leds.c" Line 34(15,20): Expect comma

I don't know why, in the CCS manual I see
Quote:
setup_uart(baud)
baud is a constant representing the number of bits per second.
A one or zero may also be passed to control the on/off status.

The program is as follows:
Code:

#include<33FJ32MC202.h>
#device adc=10

#FUSES NOWDT            // No Watch Dog Timer
#FUSES ICS0             // ICD communication channel 0 
#FUSES NOJTAG           // JTAG disabled   
#FUSES NODEBUG          // No Debug mode for ICD
#FUSES NOPUT            // No Power Up Timer
#FUSES WPOSTS1          // Watch Dog Timer PostScalar 1:1     
#FUSES WPRES128         // Watch Dog Timer PreScalar 1:128     
#FUSES NOWINDIS         // Watch Dog Timer in Window mode     
#FUSES EC               // High speed Osc (> 4mhz)
#FUSES NOOSCIO          // OSC2 is general purpose output     
#FUSES FRC_PLL          // Internal Fast RC oscillator with PLL     
#FUSES NOIESO           // Internal External Switch Over mode disabled
#FUSES NOWRT            // Program memory not write protected
#FUSES NOPROTECT        // Code not protected from reading
#FUSES NOWRTB           // Boot block not write protected
#FUSES NOBSS         // No boot segment
#use delay(clock=10000000)

#use rs232(baud=9600, BITS =8, PARITY=N , STOP=1)


#use standard_io(A)
#use standard_io(B)         // 16 bits


void main()
{
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_spi(SPI_SS_DISABLED);

   [b]setup_uart(TRUE);[/b]
   for(;;)
   {
      output_high(pin_B0);
         delay_ms(500);
         output_high(pin_B1);
         delay_ms(500);
   
         printf("hola");
   
         output_b(0);
    }
}

May somebody tell me what's wrong please????

Regards
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 16, 2019 10:42 am     Reply with quote

This statement is wrong:
Quote:
#use rs232(baud=9600, BITS =8, PARITY=N , STOP=1)

You have no pins defined or no "UART1" defined. You need to add that.
rfjhh



Joined: 31 Mar 2011
Posts: 51
Location: Mexico

View user's profile Send private message

PostPosted: Fri Aug 16, 2019 11:23 am     Reply with quote

It was included but an error message was sent:

*** Error 100 "Prueba_CCS_01_leds.c" Line 22(5,57): USE parameter value is out of range No UART defined, May need #PIN_SELECT

That's why I deleted it.

Now I tried again. Same results
#use rs232(baud=9600, BITS =8, PARITY=N , STOP=1, UART1)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 16, 2019 12:54 pm     Reply with quote

See the post that's above your post on the main forum screen.
Sticky: How to use #pin_select
http://www.ccsinfo.com/forum/viewtopic.php?t=55097
rfjhh



Joined: 31 Mar 2011
Posts: 51
Location: Mexico

View user's profile Send private message

PostPosted: Sat Aug 17, 2019 7:13 pm     Reply with quote

Yes, by using

#PIN_SELECT U1RX=PIN_B1
#PIN_SELECT U1TX=PIN_B0
#use rs232(baud=9600, BITS =8, PARITY=N , STOP=1, UART1)
Now there's no problems on building.

Now I'll to test the operation.
rfjhh



Joined: 31 Mar 2011
Posts: 51
Location: Mexico

View user's profile Send private message

PostPosted: Sat Aug 17, 2019 8:34 pm     Reply with quote

The communication is not working

printf("Hello world");

Nothing in the virtual terminal
Ttelmah



Joined: 11 Mar 2010
Posts: 19497

View user's profile Send private message

PostPosted: Sun Aug 18, 2019 12:19 am     Reply with quote

On these chips, all 'analog' pins, wake up set to analog mode. This has
priority over all digital I/O:
Quote:

The AD1PCFGL register has a default value of 0x0000;
therefore, all pins that share ANx functions are analog
(not digital) by default.

You show the analog selection line correctly, so, what compiler version are
you using?. There was a fault on this with some compilers.
The two pins you are using are AN2 & AN3.

Also, how are you getting your clock?.

You need to use 'INTERNAL=' not 'CLOCK='. This will then force the
compiler to setup the PLL. Currently this will be unprogrammed.
When you do this it should complain that 10MHz, is not a legal frequency.
It isn't available from the internal clock.

Use:

#use delay(internal=14MHz)

This should give 13.97MHz.

This line is wrong:

setup_spi(SPI_SS_DISABLED);

That enables SPI1, with slave select disabled. The syntax to disable SPI1
is:

setup_spi(FALSE);
rfjhh



Joined: 31 Mar 2011
Posts: 51
Location: Mexico

View user's profile Send private message

PostPosted: Sun Aug 18, 2019 4:19 pm     Reply with quote

Sorry Ttelmah my problem is with UART1.
I don't know how to assign pins with #PIN_SELECT

I've tried
Code:

#PIN_SELECT U1RX=PIN_B0
#PIN_SELECT U1TX=PIN_B1
#use rs232(baud=9600, BITS =8, PARITY=N , STOP=1, UART1)

void main()
{
setup_uart(TRUE);
         for(;;)
   {
      printf("Hello world");
      delay_ms(500);
        }
}

and I receive strange characters on the virtual terminal.
I don't know what am I doing wrong.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 18, 2019 4:25 pm     Reply with quote

Do the LED test to check if your processor speed is setup correctly.

Blink an LED at a 1 Hz rate:
Code:
while(TRUE)
  {
   output_toggle(PIN_B2);  // Assumes you have an LED on pin B2
   delay_ms(500);
  }

Then count the blinks for 10 seconds. Is the LED really blinking
at 1 blink per second ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19497

View user's profile Send private message

PostPosted: Mon Aug 19, 2019 12:25 am     Reply with quote

The reason you are receiving strange characters, is because of the clock.
The point is the chip can't run at 10MHz with the internal clock.
If you did the clock setup with the keyword 'INTERNAL', the compiler
would know you are trying to use the internal clock and tell you that this
speed is impossible. The chip will actually be running at a different rate, so
the baud rate will be wrong, hence the strange characters.
Your UART setup is correct. It is the chip clock that is wrong.
rfjhh



Joined: 31 Mar 2011
Posts: 51
Location: Mexico

View user's profile Send private message

PostPosted: Fri Aug 23, 2019 7:26 pm     Reply with quote

The problem is fixed:
Code:

#include<33FJ32MC202.h>
#device adc=10

#FUSES NOWDT            // No Watch Dog Timer
#FUSES ICS0             // ICD communication channel 0 
#FUSES NOJTAG           // JTAG disabled   
#FUSES NODEBUG          // No Debug mode for ICD
#FUSES NOPUT            // No Power Up Timer
#FUSES WPOSTS1          // Watch Dog Timer PostScalar 1:1     
#FUSES WPRES128         // Watch Dog Timer PreScalar 1:128     
#FUSES NOWINDIS         // Watch Dog Timer in Window mode     
#FUSES EC               // High speed Osc (> 4mhz)
#FUSES NOOSCIO          // OSC2 is general purpose output     
#FUSES FRC              // Internal Fast RC oscillator     
#FUSES NOIESO           // Internal External Switch Over mode disabled
#FUSES NOWRT            // Program memory not write protected
#FUSES NOPROTECT        // Code not protected from reading
#FUSES NOWRTB           // Boot block not write protected
#FUSES NOBSS         // No boot segment
#use delay(clock=7.37MHz)

#use standard_io(A)
#use standard_io(B)         // 16 bits
#PIN_SELECT U1RX=PIN_B0
#PIN_SELECT U1TX=PIN_B1
#use rs232(baud=9600, BITS =8, PARITY=N , STOP=1, UART1)

void main()
{
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_spi(SPI_SS_DISABLED);

   setup_uart(TRUE);
   for(;;)
   {
   output_high(pin_B2);
   delay_ms(500);
   output_low(pin_B2);
   delay_ms(500);
            
   printf("\r\n Hello world");
   }
}

Now it works

You were right Ttelmah, it's a matter of clock

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19497

View user's profile Send private message

PostPosted: Sat Aug 24, 2019 12:20 am     Reply with quote

Code:

#FUSES NOWDT            // No Watch Dog Timer
#FUSES ICS0             // ICD communication channel 0
#FUSES NOJTAG           // JTAG disabled   
#FUSES NODEBUG          // No Debug mode for ICD
#FUSES NOPUT            // No Power Up Timer
#FUSES WPOSTS1          // Watch Dog Timer PostScalar 1:1     
#FUSES WPRES128         // Watch Dog Timer PreScalar 1:128     
#FUSES NOWINDIS         // Watch Dog Timer in Window mode     
//#FUSES EC               // High speed Osc (> 4mhz)
//This is wrong. You are _not_ using an EC oscillator
//This is being overridden by the FRC setting below.

#FUSES NOOSCIO          // OSC2 is general purpose output     
//#FUSES FRC              // Internal Fast RC oscillator     
//If you use the 'internal' keyword, this is not needed.

#FUSES NOIESO           // Internal External Switch Over mode disabled
#FUSES NOWRT            // Program memory not write protected
#FUSES NOPROTECT        // Code not protected from reading
#FUSES NOWRTB           // Boot block not write protected
#FUSES NOBSS         // No boot segment
#use delay(INTERNAL=7.37MHz)
//Just use 'INTERNAL' here, and the compiler will correctly set the
//oscillator fuses for you. It'll also set the PLL, if you ask for a higher
//frequency, and tell you if the frequency can't be done...


Comments inline
rfjhh



Joined: 31 Mar 2011
Posts: 51
Location: Mexico

View user's profile Send private message

PostPosted: Sat Aug 24, 2019 12:56 pm     Reply with quote

Can you tell me how to use the dsp motor with ccs?
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Aug 24, 2019 3:56 pm     Reply with quote

you need to supply a link or part number for the 'dsp motor' you have.
rfjhh



Joined: 31 Mar 2011
Posts: 51
Location: Mexico

View user's profile Send private message

PostPosted: Sat Aug 24, 2019 5:42 pm     Reply with quote

I'm using dsPIC33FJ32MC202
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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