SPI & UART

  
The easyRadio Integrated Controller.

Moderators: radiomadeeasy, WirelessMike

SPI & UART

Postby morganferrari » Tue May 02, 2017 8:14 am

Hello, I work on a project with eric4 dev kit. The main subject is to connect a MAX31855PMB1 (thermocouple type K mesurement with SPI) to one erci4 and the other on my laptop.
I develop a software to start the acquisition, display the data in a graph and stop this same acquisition and put the second eric4 in low consumption. I begin the porject but I have some problems with SPI....

this is my code: I have good numerical signal on MI with my oscilloscope but no good values on TempHB & TempLB .... On the eric4 recptor and easyradiocompanion , I could read 0XFF 0XFF.......
I try to use "eRIC_RfDataReceivedInterrupt()" function to wait for a start & stop command but no way...

#include<cc430f5137.h>
#include "eRIC.h"
#define SPI_MAX31855
#define Transmit_Val
#define Pin2_CTS() Pin2_FunctionUartABusy();
#define Pin5_RTS() {Pin5_SetAsInput();Pin5_PullDownEnable();}

int main(void)
{
eRIC_WDT_Stop(); //Stop watch dog timer, just in case
eRIC_GlobalInterruptDisable(); //Global interrupts disabled
eRIC_SetCpuFrequency(5000000); //Sets CPU clock to 5mHz
Pin15_SetAsOutput(); //Set pin15 output CS
Pin17_SetAsOutput(); //Set pin17 output LED
eRIC_UARTAInitialise(19200); //Initialise Uart with 19200 baud to send captured value
Pin3_FunctionUartATxOUT();
Pin4_FunctionUartARxD();
eRIC_Rx_Enable();
eROS_Initialise(434000000);//Initialise Freq with 433MHz
eRIC_SpiAInitialise(5000000);//Initialise SPI with 5MHz CLK
eRIC_SpiARxIsEnabled();
eRIC_SpiATxIsEnabled();
Pin21_FunctionSpiA_MI();//Pin21 MI
Pin20_FunctionSpiA_SCLKOUT();//Pin20 CLK
eRIC_SpiA_3PinMode();// 3 pin MODE
eRIC_SpiA_MasterMode();//Master mode
eRIC_GlobalInterruptEnable();
volatile int TempHB = 0;
volatile int TempLB = 0;
volatile unsigned int TC = 0,recep=0;
Pin15_SetHigh();
eRIC_Delay(1);
while(1)
{
#ifdef SPI_MAX31855
Pin15_SetLow();
TempHB=eRIC_SpiARead(0xFF);
while(eRIC_SpiARxBufferIsEmpty());
TempLB=eRIC_SpiARead(0xFF);
while(eRIC_SpiARxBufferIsEmpty());
Pin15_SetHigh();
TC=TempHB<<8|TempLB;
TC=TC>>2 & 0X3FFF;
#endif

#ifdef Transmit_Val
/*Pin17_SetHigh();
eRIC_UartASendByte(TC>>8); //send high byte to Uart
while(eRIC_UartATxBufferIsBusy());
eRIC_UartASendByte(TC); //send low byte to Uart
*/
while(eRIC_UartATxBufferIsBusy());
eRIC_RadioTx_BuffCount = 0;
eRIC_RadioTx_Buffer[eRIC_RadioTx_BuffCount++] = TC>>8; //send high byte over air
eRIC_RadioTx_Buffer[eRIC_RadioTx_BuffCount++] = TC; //send low byte over air
eRIC_RfSenddata();//send data
eRIC_Delay(100);
Pin17_SetLow();
eRIC_Delay(100);
#endif
}//end of while(1)
}//end of main()

void eRIC_RfDataReceivedInterrupt() // Add code here to deal with available received data..THis is triggered when interrupt is enabled and a packet is received
{
volatile unsigned int recep=0;
if(eRIC_Rxdata_available)
{
recep = eRIC_ReadRfByte(); //Reads
Pin17_SetHigh();
eRIC_Delay(250);
Pin17_SetLow();
eRIC_Delay(250);
//eRIC_RadioTx_BuffCount = 0;
//eRIC_RadioTx_Buffer[eRIC_RadioTx_BuffCount++] = recep; //send low byte over air
//eRIC_RfSenddata();//send data
}

}
morganferrari
 
Posts: 0
Joined: Wed Apr 19, 2017 3:05 pm

Re: SPI & UART

Postby radiomadeeasy » Thu May 11, 2017 11:36 am

You have used eRIC_RfDataReceivedInterrupt(); but not enabled it.

Please add eRIC_RfDataReceivedInterruptEnable(); in main.

When this interrupt is enabled, eRIC_RfDataReceivedInterrupt(); function is interrupted whenever there is some data received over air.
radiomadeeasy
User avatar
radiomadeeasy
Administrator
 
Posts: 58
Joined: Mon Sep 17, 2012 1:14 pm

Re: SPI & UART

Postby morganferrari » Thu May 11, 2017 12:43 pm

Hello, thanks. I try it but it doesn't work

#include<cc430f5137.h>
#include "eRIC.h"
#include <stdio.h>
#include <string.h>

int main(void)
{
eRIC_WDT_Stop(); //Stop watch dog timer, just in case
eRIC_GlobalInterruptDisable(); //Global interrupts disabled
eRIC_SetCpuFrequency(5000000); //Sets CPU clock to 5mHz
Pin15_SetAsOutput(); //Set pin15 output CS
Pin17_SetAsOutput(); //Set pin17 output LED
Pin18_SetAsOutput(); //Set pin18 output LED
eRIC_UARTAInitialise(19200); //Initialise Uart with 19200 baud to send captured value
Pin3_FunctionUartATxOUT();
//Pin4_FunctionUartARxD();
eRIC_Rx_Enable();
eROS_Initialise(434000000);//Initialise Freq with 433MHz
eRIC_SpiAInitialise(5000000);//Initialise SPI with 5MHz CLK
eRIC_SpiARxIsEnabled();
eRIC_SpiATxIsEnabled();
Pin21_FunctionSpiA_MI();//Pin21 MI
Pin20_FunctionSpiA_SCLKOUT();//Pin20 CLK
eRIC_SpiA_3PinMode();// 3 pin MODE
eRIC_SpiA_MasterMode();//Master mode
eRIC_SpiA_8Bit();
eRIC_SpiA_MsbFirst();
eRIC_SpiA_SyncMode();
eRIC_GlobalInterruptEnable();
eRIC_RfDataReceivedInterruptEnable();//V1.1
eRIC_UartARxInteruptEnable();

volatile int TempHB = 0;
volatile int TempLB = 0;
volatile unsigned int TC = 0,recep;

Pin15_SetHigh();
eRIC_Delay(1);

while(recep==0)
{
Pin15_SetLow();
TempHB=eRIC_SpiARead(0xFF);
while(eRIC_SpiARxBufferIsEmpty());
TempLB=eRIC_SpiARead(0xFF);
while(eRIC_SpiARxBufferIsEmpty());
Pin15_SetHigh();
TC=(TempHB<<8|TempLB)>>2;
Pin17_SetHigh();
eRIC_RadioTx_BuffCount = 0;
eRIC_RadioTx_Buffer[eRIC_RadioTx_BuffCount++] = TC>>8; //send high byte over air
eRIC_RadioTx_Buffer[eRIC_RadioTx_BuffCount++] = TC; //send low byte over air
eRIC_RfSenddata();//send data
eRIC_Delay(75);
Pin17_SetLow();
eRIC_Delay(75);
}
// enter lowpower mode but RF receive is activate by eRIC_RfDataReceivedInterrupt()
}//end of main()

void eRIC_RfDataReceivedInterrupt() // Add code here to deal with available received data..THis is triggered when interrupt is enabled and a packet is received
{
volatile unsigned int recep=0;
while(eRIC_Rxdata_available)
{
recep = eRIC_ReadRfByte(); //Reads
eRIC_Delay(500);
Pin18_SetLow();
eRIC_Delay(500);
Pin18_SetHigh();
eRIC_Delay(500);
Pin18_SetLow();
eRIC_RfDataReceivedInterruptFlag_Clear()
}
}
morganferrari
 
Posts: 0
Joined: Wed Apr 19, 2017 3:05 pm

Re: SPI & UART

Postby srikanth.ganji » Mon May 15, 2017 10:05 am

THere are two threads opened under MorganFerrari. Can you please only respond to this thread to avoid confusion. In other thread here viewtopic.php?f=12&t=139 , you said you have succeded in sending data with eRIC module.

So can you please confirm if the problem is resolved? THanks
srikanth.ganji
Administrator
 
Posts: 21
Joined: Thu Oct 04, 2012 10:41 am

Re: SPI & UART

Postby morganferrari » Mon May 15, 2017 4:05 pm

Hello, on this topic i sent you my last code. With it, I succeed in sending the data of MAX31855 to the other eric4 module. I read the HEX values with easy radio companion (In the receiver I let the original program....).

Now I want to send a start and a stop command with this module and put the first module in low power mode till it receive a start.

I'm agree with you to close the other topic.

Regards.
morganferrari
 
Posts: 0
Joined: Wed Apr 19, 2017 3:05 pm

Re: SPI & UART

Postby srikanth.ganji » Wed May 17, 2017 2:36 pm

Hi,
Thanks. Let me know if you need help in writing start,stop command and setting lowpower modes.
You can find some code examples here: http://www.lprs.co.uk/knowledge-centre/code-examples.html
You can download low power mode example here: http://www.lprs.co.uk/assets/files/eRIC_LowPowerMode_V1.1.zip
Thanks
srikanth.ganji
Administrator
 
Posts: 21
Joined: Thu Oct 04, 2012 10:41 am

Re: SPI & UART

Postby morganferrari » Wed May 17, 2017 3:36 pm

Hello, I try to understand the code example's but I don't suceed.
You can see my last code on this post "Re: SPI & UART Postby morganferrari » Thu May 11, 2017 12:43 pm"

see here a zoom on my code

Recep is the variable for the start & stop data. Start is 0 value and stop is other. If recep is equal to 0 , i send on air the spi value frop MAX31855... If not I i put module on low power mode. i want to have an interruption when i receive a new data on air

while(recep==0)
{
Pin15_SetLow();
TempHB=eRIC_SpiARead(0xFF);
while(eRIC_SpiARxBufferIsEmpty());
TempLB=eRIC_SpiARead(0xFF);
while(eRIC_SpiARxBufferIsEmpty());
Pin15_SetHigh();
TC=(TempHB<<8|TempLB)>>2;
Pin17_SetHigh();
eRIC_RadioTx_BuffCount = 0;
eRIC_RadioTx_Buffer[eRIC_RadioTx_BuffCount++] = TC>>8; //send high byte over air
eRIC_RadioTx_Buffer[eRIC_RadioTx_BuffCount++] = TC; //send low byte over air
eRIC_RfSenddata();//send data
eRIC_Delay(75);
Pin17_SetLow();
eRIC_Delay(75);
}
// enter lowpower mode but RF receive is activate by eRIC_RfDataReceivedInterrupt()
}//end of main()

void eRIC_RfDataReceivedInterrupt() // Add code here to deal with available received data..THis is triggered when interrupt is enabled and a packet is received
{
volatile unsigned int recep=0;
while(eRIC_Rxdata_available)
{
recep = eRIC_ReadRfByte(); //Reads
eRIC_Delay(500);
Pin18_SetLow();
eRIC_Delay(500);
Pin18_SetHigh();
eRIC_Delay(500);
Pin18_SetLow();
eRIC_RfDataReceivedInterruptFlag_Clear()
}
}
morganferrari
 
Posts: 0
Joined: Wed Apr 19, 2017 3:05 pm

Re: SPI & UART

Postby morganferrari » Tue May 30, 2017 8:31 am

Hi,
My entire code has been posted on this topic. I don't want to modify the code on The module, which is wired on my laptop. It is "eRICxeasyRadioV1.5.5". But i have only to developp a code for the other module; I just want help to write "start", "stop" from a labview interface and put it on "lowpowermode". I have already write the code for the MAX31855 (spi dialog....)

this is the parts which has to to completed start is equal to 0 and stop 1

void eRIC_RfDataReceivedInterrupt() // Add code here to deal with available received data..THis is triggered when interrupt is enabled and a packet is received
{
volatile unsigned int recep=0;
while(eRIC_Rxdata_available)
{
recep = eRIC_ReadRfByte(); //Reads
eRIC_Delay(500);
Pin18_SetLow();
eRIC_Delay(500);
Pin18_SetHigh();
eRIC_Delay(500);
Pin18_SetLow();
eRIC_RfDataReceivedInterruptFlag_Clear()
}
}

the second one

while(recep==0)
{
Pin15_SetLow();
TempHB=eRIC_SpiARead(0xFF);
while(eRIC_SpiARxBufferIsEmpty());
TempLB=eRIC_SpiARead(0xFF);
while(eRIC_SpiARxBufferIsEmpty());
Pin15_SetHigh();
TC=(TempHB<<8|TempLB)>>2;
Pin17_SetHigh();
eRIC_RadioTx_BuffCount = 0;
eRIC_RadioTx_Buffer[eRIC_RadioTx_BuffCount++] = TC>>8; //send high byte over air
eRIC_RadioTx_Buffer[eRIC_RadioTx_BuffCount++] = TC; //send low byte over air
eRIC_RfSenddata();//send data
eRIC_Delay(75);
Pin17_SetLow();
eRIC_Delay(75);
}
// enter lowpower mode but RF receive is activate by eRIC_RfDataReceivedInterrupt()
}//end of main()
morganferrari
 
Posts: 0
Joined: Wed Apr 19, 2017 3:05 pm

Re: SPI & UART

Postby srikanth.ganji » Wed May 31, 2017 9:25 am

Hi ,
Can you please confirm which part is not working. IS it the module not receiving or is it not transmitting.
Can you also please confirm, if you are exiting low power mode to transmit. If the module is in low powr mode and if tranmit is not in any interrupt routine, the transmit routine will not be called by program. You will either need to exit low power mode or put transmit code in some form of interrupt routine.
Thanks
srikanth.ganji
Administrator
 
Posts: 21
Joined: Thu Oct 04, 2012 10:41 am

Re: SPI & UART

Postby morganferrari » Wed May 31, 2017 3:39 pm

hello,
I can not enter in the interrupt part when i send a "0" value with the module which is wired to my laptop (with eric companion...). bold character

#include<cc430f5137.h>
#include "eRIC.h"
#include <stdio.h>
#include <string.h>

int main(void)
{
eRIC_WDT_Stop(); //Stop watch dog timer, just in case
eRIC_GlobalInterruptDisable(); //Global interrupts disabled
eRIC_SetCpuFrequency(5000000); //Sets CPU clock to 5mHz
Pin15_SetAsOutput(); //Set pin15 output CS
Pin17_SetAsOutput(); //Set pin17 output LED
Pin18_SetAsOutput(); //Set pin18 output LED
eRIC_UARTAInitialise(19200); //Initialise Uart with 19200 baud to send captured value
Pin3_FunctionUartATxOUT();
//Pin4_FunctionUartARxD();
eRIC_Rx_Enable();
eROS_Initialise(434000000);//Initialise Freq with 433MHz
eRIC_SpiAInitialise(5000000);//Initialise SPI with 5MHz CLK
eRIC_SpiARxIsEnabled();
eRIC_SpiATxIsEnabled();
Pin21_FunctionSpiA_MI();//Pin21 MI
Pin20_FunctionSpiA_SCLKOUT();//Pin20 CLK
eRIC_SpiA_3PinMode();// 3 pin MODE
eRIC_SpiA_MasterMode();//Master mode
eRIC_SpiA_8Bit();
eRIC_SpiA_MsbFirst();
eRIC_SpiA_SyncMode();
eRIC_GlobalInterruptEnable();
eRIC_RfDataReceivedInterruptEnable();//V1.1
eRIC_UartARxInteruptEnable();

volatile int TempHB = 0;
volatile int TempLB = 0;
volatile unsigned int TC = 0,recep;

Pin15_SetHigh();
eRIC_Delay(1);

while(recep==0)
{
Pin15_SetLow();
TempHB=eRIC_SpiARead(0xFF);
while(eRIC_SpiARxBufferIsEmpty());
TempLB=eRIC_SpiARead(0xFF);
while(eRIC_SpiARxBufferIsEmpty());
Pin15_SetHigh();
TC=(TempHB<<8|TempLB)>>2;
Pin17_SetHigh();
eRIC_RadioTx_BuffCount = 0;
eRIC_RadioTx_Buffer[eRIC_RadioTx_BuffCount++] = TC>>8; //send high byte over air
eRIC_RadioTx_Buffer[eRIC_RadioTx_BuffCount++] = TC; //send low byte over air
eRIC_RfSenddata();//send data
eRIC_Delay(75);
Pin17_SetLow();
eRIC_Delay(75);
}
// enter lowpower mode but RF receive is activate by eRIC_RfDataReceivedInterrupt()
}//end of main()

void eRIC_RfDataReceivedInterrupt() // Add code here to deal with available received data..THis is triggered when interrupt is enabled and a packet is received
{
volatile unsigned int recep=0;
while(eRIC_Rxdata_available)
{
recep = eRIC_ReadRfByte(); //Reads
eRIC_Delay(500);
Pin18_SetLow();
eRIC_Delay(500);
Pin18_SetHigh();
eRIC_Delay(500);
Pin18_SetLow();
eRIC_RfDataReceivedInterruptFlag_Clear()
}
}
morganferrari
 
Posts: 0
Joined: Wed Apr 19, 2017 3:05 pm


Return to eRIC

Who is online

Users browsing this forum: No registered users and 1 guest

cron