Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] problem to send out an array from a PIC

Status
Not open for further replies.

treyz

Member level 5
Joined
Sep 26, 2012
Messages
93
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,065
Hi everyone,

I have this mistake and I don'y know why,I am just triyng to send an array via USART from pic18f4680 and I have this error:

"C:\Users\marcd\Desktop\Projects\(Slave)_RS485\(Slave)__RS485\s_code.c:99:Error [1129] [] operator requires a pointer "

Have you got any ideas about what my error could be?

Here is my piece of code:

void UART_putc(unsigned char result)
{
char i=0;
TXSTAbits.TXEN=0; //Disable transmission
TXREG = result; //Load txreg with data
TXSTAbits.TXEN=1; //Enable transmission
while(TXSTAbits.TRMT==0); ; //Wait until the byte is sent
{}
i++;
}
 

Hi,
please check the semicolon in the coding ur provided.correct it and compile;if it is not solved pls provide full coding.

while(TXSTAbits.TRMT==0); ; // check this line of coding
 

Code:
void SendMsg(void)
{
	unsigned char size;
	TXPtr=&txdata[0];
	size=sizeof(txdata);
	while(size)
	{
		while (U2STAbits.UTXBF);
		U2TXREG = *TXPtr++;
		size--;
	}
}
txdata is the array which is send. This code is for dsPIC30f4011 in microchip C30 compiler, whereas TXPtr is defined as unsigned char *. I hope this may help you.
 

Hi everyone

Thank you for replying to me

Here is the full code. I am using C18 compiler from Microchip

#include "s_code.h"
#include <p18f4680.h>

//FOSC = ECIO_EC - External Oscillator/ IO On RA6
//PCLKEN = ON - Primary Clock Enable
//FCMEN = OFF - Fail-Safe Clock Monitor disabled
//PWRTEN = OFF - Power Up Timer disabled
//BOREN = OFF - Brown-out Reset disabled in hardware and software
//WDTEN = OFF - WDT is controlled by SWDTEN bit of the WDTCON register
//MCLRE = ON - MCLR pin enabled, RE3 input pin disabled
//LVP = OFF - Single-Supply ICSP disabled
//PBADEN = OFF - PortB<4:0> are configured as digital I/O On reset
//STVREN = OFF - Stack full/underflow will not cause reset
//CPO = OFF - Code protect disabled
/*----------------------------------------------------------------------------*/
//Theses lines do some set up of the compiler and the chip. The are normally called
//configuration fuses.
/*----------------------------------------------------------------------------*/

#pragma config OSC= HS
#pragma config CP0=OFF, WDT=OFF, MCLRE=ON, PBADEN=OFF, BOREN=OFF, PWRT=OFF
#pragma config LVP=OFF, STVREN=OFF, FCMEN=OFF
//OSC=ECIO,
//#pragma code high_vector=0x08

/*-----------------------------------------------------------------------------*/
// Interrupt code section
/*----------------------------------------------------------------------------- */
#pragma code InterruptVectorLow=0x18
void InterruptVectorLow (void)
{
_asm
goto InterruptHandlerLow //jump to interrupt routine
_endasm
}
//#pragma CLOCK_FREQ 20000000

/*-----------------------------------------------------------------------------*/
// Description: Delay
/*----------------------------------------------------------------------------- */

void delay(unsigned char delayValue)
{
while(delayValue)
--delayValue;
}

/*-----------------------------------------------------------------------------*/
// Description: Configure the MSSP module for SPI
/*----------------------------------------------------------------------------- */

void init_spi() /* Initialise the PIC18F4680 SPI Peripheral*/
{
PORTA = 0x00; //Clear PORTA
PORTB = 0x00; //Clear PORTB
PORTC = 0x00; //Clear PORTC
PORTD = 0x00; //Clear PORTD
TRISCbits.TRISC0 = 0; //Set SS as an Output(chip select)
TRISCbits.TRISC5 = 0; //Set SDO as an output(Serial Data Out)
TRISCbits.TRISC4 = 1; //Set SDI as an Input(Serial Data In)
TRISAbits.TRISA6 = 1; //Set for External Oscillator
SSPCON1 = 0x24; //Enable SPI Slave with clock on SCK pin.
SSPSTAT = 0x40; //Set SMP=0 and CKE=1. Notes: The lower 6 bit is read only
PORTCbits.RC0 = 1; //Disable Chip Select or ss
INTCON = 0x80; //Enable Interruptions
}

/*-----------------------------------------------------------------------------*/
// Initialization of UART
/*----------------------------------------------------------------------------- */
void init_uart(void) // init UART module for 9600bps boud, start bit 1, stopbit 1, parity NONE
{
cUART_data_flg=0; //Init data receive flag to zero (no data)
TRISCbits.TRISC7=1; //Make UART RX pin input
TRISCbits.TRISC6=0; //Make UART TX pin output
SPBRGH = 0x00; //9600bps 20MHz Osc
SPBRG = 0x81;

RCSTAbits.CREN=1; //1 = Enables receiver
RCSTAbits.SPEN=1; //1 = Serial port enabled (configures RX/DT and TX/CK pins as serial port pins)
RCSTAbits.RX9 = 1; //1 = 9-bit Receive Enable bit
BAUDCONbits.BRG16=1; //1 = 16-bit Baud Rate Generator – SPBRGH and SPBRG

TXSTAbits.SYNC=0; //0 = Asynchronous mode
TXSTAbits.BRGH=1; //1 = High speed
TXSTAbits.TXEN=1; //1 = Transmit enabled

RCONbits.IPEN = 1; //Enable Interrupt priority levels
IPR1bits.RCIP=0; //EUSART Receive Interrupt Priority 0 = Low priority
PIE1bits.RCIE=1; //1 = Enables the EUSART receive interrupt
INTCONbits.GIEL = 1; //Enable interrupts
INTCONbits.GIEH = 1;
}

void UART_putc(unsigned char result)
{
char i=0;
TXSTAbits.TXEN=0; //Disable transmission
TXREG = result; //Load txreg with data
TXSTAbits.TXEN=1; //Enable transmission
while(TXSTAbits.TRMT==0); //Wait until the byte is sent
{}
i++;
}
/*---------------------------------------------------------------------------------*/
// Initialize Interrupts
/*---------------------------------------------------------------------------------*/

void init_interrupt (void)
{
RCON |= 0x80;
INTCONbits.PEIE = 1;
INTCONbits.GIE = 1;
INTCON2bits.INTEDG0 = 0;
INTCONbits.INT0IE = 1;
}
//----------------------------------------------------------------------------
// Low priority interrupt routine
//----------------------------------------------------------------------------

#pragma code
#pragma interrupt InterruptHandlerLow

void InterruptHandlerLow(void)
{
if (PIR1bits.RCIF==1) //Is interrupt occured by EUSART receive?,
//Then RCREG is full we have new data (cleared when RCREG is read)
{
if(RCSTA&0x06) //More efficient way than following commented method to check for reception error
//If(RCSTAbits.FERR==1 || RCSTAbits.OERR==1 )
{
RCSTAbits.CREN=0; //Overrun error (can be cleared by clearing bit CREN)
cUART_char=RCREG; //Clear Framing error
RCSTAbits.CREN=1;
}
else
{
cUART_char = RCREG; //Read new data into variable
cUART_data_flg = 1; //New data received. so enable flg
}
}
}

/*-----------------------------------------------------------------------------*/
// Description: Read from the SPI (Slave)
/*----------------------------------------------------------------------------- */
unsigned char SPI_Read( void )
{ char i;
unsigned char result[32];
// result = SSPBUF; // Clear BF
PIR1bits.SSPIF = 0; // Clear interrupt flag
SSPBUF = 0x00; // Initiate bus cycle

while(!PIR1bits.SSPIF); // Wait until cycle complete
return ( SSPBUF ); // Return with byte read
}

/*----------------------------------------------------------------------*/
void main()
{
unsigned char result[32];

int j=0;
init_spi(); // init SPI module.
init_uart(); // init UART module
init_interrupt();

while(1) // infinite loop which handles incoming data as they arrive

{
SPI_Read();
// if(SSPBUF = ......)
{
UART_putc(cUART_char);//then I would like to send that array via RS485.....still thinking about it
}

}
}
 
Last edited:

#include<pic.h>
#include"pic_lcd8.h"
unsigned char a[4]={'p','i','c',1'},i;
void main()
{
TRISC=0x00;
TRISD=0x00;
Lcd8_Init();
Lcd8_Display(0x80,"serial commn",12);
Delay(65000);Delay(65000);
SPBRG=25;
BRGH=1;
SYNC=0;
SPEN=1;
TXEN=1;
GIE=1;
PEIE=1;
while(TXIF)
{
for(i=0;i<4;i++)
{
TXREG= a;
Delay(65000);


}
}
TXIF=0;

}


hope the above mensioned code will help u...
 

Hi BISH,

I can't do that because I am using SPI communication. I am following the same process as you did.
But I still can't see where is my mistake...:-(

- - - Updated - - -

Hi,

I think I know my mistake, I realized that I can't send a array via USART( my array is result which is a frame such as STX-ADDR-DATA-ETX), because it is just allowed to send 1 byte(8 bit), not an array. So I am going to find a way to send this frame in another way.

Thank anyway!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top