View previous topic :: View next topic |
Author |
Message |
jeremy57350
Joined: 11 Jan 2012 Posts: 14
|
MRF89XA |
Posted: Sun May 06, 2012 3:21 am |
|
|
hello, I made a small program for my transmission module, and I do not understand why it does not work.
A problem of waking up?
Wrong setting?
Help please :(
Code principal:
Code: |
#include <18F2580.h>
#include <MRF89XA.h>
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H
#use delay (clock=4000000)
#int_timer2
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,BITS=8) //exemple pour 9600bds et émission sur C6 et réception sur C7
#use spi(FORCE_HW,BITS=8, stream=SPI_STREAM)
//#include "LCD Picdem2.c"
#define MASTER_CS PIN_c0 // selection spi donnée
#define DATA_CS PIN_c1 // selection spi configuration
void RegisterSet(BYTE address, BYTE value)
{
output_low(MASTER_CS);
address = (address<<1);
spi_write (address);
spi_write (value);
output_high(MASTER_CS);
}
void WriteFIFO(BYTE data )
{
output_low(DATA_CS);
spi_write(Data);
output_high(DATA_CS);
delay_ms(100);
}
void main(void)
{
//set_tris_c (0b11010001);
setup_spi (spi_master|SPI_MODE_0);
//setup_oscillator( OSC_4MHZ );
//output_low(MASTER_CS);
//output_low(DATA_CS);
//delay_ms(200);
output_high(MASTER_CS);
output_high(DATA_CS);
delay_ms(100);
RegisterSet(REG_MCPARAM0, RF_TRANSMITTER | FREQBAND_950 | VCO_TRIM_11, );
//lcd_init();
while(true)
{
int toto=25;
delay_ms(20);
writeFIFO(toto);
delay_ms(100);
}
}
|
header microchip. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sun May 06, 2012 11:19 am |
|
|
We need more information.
What doesn't 'wakeup' the PIC or the peripheral device ?
I don't see where you tell the PIC to go to sleep though.
You should add a couple of LEDs and toggle them at 'key' points of your program to confirm the PIC does what you think it should.
Since you seem to have an LCD as well as PC link, perhaps send them 'messages' as to the state of the program(step 1,2,3,etc). |
|
|
jeremy57350
Joined: 11 Jan 2012 Posts: 14
|
|
Posted: Sun May 06, 2012 1:51 pm |
|
|
I thought was a problem of waking up the module MRF89XA, or parameters parametrais evil, have you ever work with this module? |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun May 06, 2012 2:01 pm |
|
|
Quote: |
have you ever work with this module?
|
Does it matter?
The guy's trying to help you, so don't be rude.
I agree you are NOT giving enough information.
You've got a problem, otherwise you would not be asking.
It's often the case that you're looking in the wrong place.
CCS don't pay us to provide help.
That's why we ask awkward questions.
Mike |
|
|
jeremy57350
Joined: 11 Jan 2012 Posts: 14
|
|
Posted: Sun May 06, 2012 2:22 pm |
|
|
I do not think it was annoying and I'm sorry to offended, I thank you in advance for your help. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Sun May 06, 2012 2:37 pm |
|
|
Ignoring the module for a moment, there are some severe problems with the code as posted:
1) _Except_ for the device header file, in general 'includes', _must_ be after the system configuration lines (clock, fuses RS232 etc.). Otherwise if any of the features using these (delays, serial I/O etc.) are used in the include file, they won't work.
It doesn't appear as if the posted code actually uses the include file, but correct this.
2) The definition #INT_TIMERx, is meant to be followed by the routine to handle this interrupt. Having it floating in the middle of the configuration lines, may well result in invalid code.....
3) Then you are mixing SPI operation methods. You need to _either_ use '#USE SPI', and include a mode definition here, _or_ use setup_spi. If you use the latter, then you must use 'spi_xfer' to actually send/receive, as opposed to spi_read/spi_write. I'd doubt if the SPI is actually setup as you want....
4) You have two 'chip selects' (called 'CSCON', and CSDAT on the chip). Your patterns need to be to drop CSCON to access the config registers, or drop CSDAT to access the data registers. It is not clear from your 'master_cs' name, which line you are dropping, but hopefully this is the CSCON line.
5) Look at the data sheet. You are only setting the GCONFIG register. You need to set several more values before the chip will be ready to run.
6) Are you making connections to the IRQ lines. You _will_ need to be able to poll these at least.
Best Wishes |
|
|
jeremy57350
Joined: 11 Jan 2012 Posts: 14
|
|
Posted: Sun May 06, 2012 3:09 pm |
|
|
thank you for your help
1. If I understand you well I have to remove the 232 and fix my problem came out with an example TRIS_C
2. my # int_timer came from an old program, so has excluded entirely
3. I thought my SPI bus has functioned properly because the oscilloscope I was reporting the correct values.
I think most used out # use_spi because I have more KNOWLEDGE for this.
I should then set encors other address, even if it defaults are set by
MASTER_CS my line is well connected and has CS_CON I did not think the IRQ input is important for transmission but only to receive an interrupt with
ps: Sorry for language mistakes I'm doing better or worse in English |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Mon May 07, 2012 8:50 am |
|
|
Quote: |
I do not think it was annoying and I'm sorry to offended, I thank you in advance for your help.
|
Apology accepted.
You're being told to put the basics right first. Then you have a chance of getting your module to work.
Best of luck.
Mike |
|
|
jeremy57350
Joined: 11 Jan 2012 Posts: 14
|
|
Posted: Mon May 07, 2012 1:44 pm |
|
|
Thank you, when you said to the first base to right, I must change what program?
I vien because today I try again this is still nothing unfortunately. |
|
|
|