BiNa2605
Full Member level 3
- Joined
- Sep 1, 2015
- Messages
- 179
- Helped
- 6
- Reputation
- 12
- Reaction score
- 4
- Trophy points
- 18
- Location
- VietNam
- Activity points
- 1,357
#define SEN PORTC.B1
#define WRITE 0x0000
#define READ 0x4000
#define PAGE_WR 0x0800
unsigned int uiTemp=0;
//Write function for the SPI interface
void SL900A_Write(unsigned int uiMode, unsigned int uiAddress, unsigned char ucData){
SEN = 1; //Enable Slave select
delay_us(500); //SEN to first SCLK rising edge setup time
//Transmit 16 bit data
uiTemp = (uiMode&0xff00) | uiAddress;
SPI1_Write(uiTemp);
SPI1_Write(ucData); //Data need to transmit
delay_ms(1);
SEN = 0; //Stop
}
void main()
{
unsigned char ucwrData, ucMo;
unsigned int uiMo, uiAdd,i,uiTemp1;
//FOSC = 0b110; INTOSC oscillator
//OSCCON = 0b01011010; //Internal Oscillator 1Mhz --- SL900A -> 1.5v
//OSCCON = 0b01101010; //Internal Oscillator 4Mhz
OSCCON = 0b01110010; //Internal Oscillator 8Mhz
//OSCCON = 0b01111010; //Internal Oscillator 16Mhz
TRISC.B1 = 0; //RC1 output Select SPI
PORTC.B1 = 1;
TRISB.B4 = 0; //RB4 output test led
//SPI
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
//SPI1_Init();
//Choose MODE in here
uiMo = WRITE;
//uiAdd = 0x047E; //the last physical address of SL900A User_Memory
uiAdd = 0; //The first physical address of SL900A User_Memory
ucwrData = 0x01;
for (i=0;i<100;i++){
SL900A_Write(uiMo,uiAdd+i,ucwrData);
delay_ms(1);
}
while(1){
PORTB.B4 = 0;
//delay_ms(100);
//PORTB.B4 = 0;
//delay_ms(100);
}
}
SPI1_Write(uiTemp >> 8);
SPI1_Write(uiTemp);
The MCU operate at Master mode. So do I need to use SS pin or I just use optional pin for the chip select when applying SPI. I read the datasheet and some applications.Another thing to check is the ANSELA register. Your diagram show you are using the pin called /SS which can be RA0 or RA5 depending on the alternate pin configuration but both are on PORTA. The SDI and SDO pins are shared with PORTC. By default PORTA is configured for analog input, have you ensured the ANSELA bit corresonding to your select output is '0' (digital mode)?
I ask the using PORTC.B1 as an chip select is it wrong or right. Actually my hardware and software matched.Simple answer: Hardware and software must match
When I compare with the referenceBy the way, I would disagree that the scope traces are looking better. The bottom picture seems to have a signal that is varying by less that 200mV and it also has a huge level of noise.
for (i=0;i<100;i++){
SL900A_Write(uiMo,uiAdd+i,ucwrData);
delay_ms(1);
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?