SPI Exception TC65 | Telit Cinterion IoT Developer Community
January 31, 2015 - 11:12pm, 3756 views
Hello,
I am working with TC65 SPI interface connection .
The PCB board --interface-- is under manufacturing.I am testing the code without any external connection right now and I am receiving an SPI class Connection exception as you can see below.
The cinterion is going to connect thru via SPI to a ***im driver 6950 in order to control 7 segment led.In order to do that In a first stage the 6950 chip must be initialized in order to receive the main data.
Thank you
Exception Error>
- javax.microedition.io.Connec
tor.open(), bci=12
- javax.microedition.io.Connector.open(), bci=3
- javax.micro
edition.io.Connector.open(), bci=2
- midlet300.Midlet300$SPICommunicator.openSPI
(), bci=3
- midlet300.Midlet300$PortListener.run(), bci=34
Uncaught exception: ja
va.lang.NullPointerException: 0
- midlet300.Midlet300$SPICommunicator.send(),
bci=94
- midlet300.Midlet300$SPICommunicator.sendCommand(), bci=2
- midlet300.Mi
dlet300$SPICommunicator.setup(), bci=3
- midlet300.Midlet300$PortListener.run(),
bci=39
Partial Code
import com.siemens.icm.io.SpiConnection;
public void run(){
int ficha=3;
int cont=0;
int value=0;
POST post =new POST();
SPICommunicator spiCommunicator=new SPICommunicator();
spiCommunicator.openSPI();
// ***im6950 should be initialized to receive data
spiCommunicator.setup();
double FinalValue;
try{
while(true){
Thread.sleep(1000);
if(gpio4==true){
cont++;
if(cont%ficha==0){
value=cont;
if(gpio6==true){
cont=0;
}
//Sending partial value through SPI channel
spiCommunicator.displayNumber(value);
System.out.println("Valor parcial:" + value);
}
}
if(terminated)
break;
}
/*
*****************************************************************
Preparing to send the final value to SPI CHANNEL
*****************************************************************
*/
FinalValue=(double)(value *mensaje)/12;
System.out.println("Tarifa a pagar:" + FinalValue);
int spiValue=(int) FinalValue;
spiCommunicator.displayNumber(spiValue);
spiCommunicator.closeSPI();
}catch(InterruptedException e) {
e.printStackTrace();
}
}
/*
****************************************************************************
SPI Class: ***6950 Setup according the technical information
****************************************************************************
*/
public class SPICommunicator{
SpiConnection spiConn;
InputStream isSPI;
OutputStream osSPI;
public void openSPI(){
try{
spiConn = (SpiConnection) Connector.open("spi:0;baudrate=100;clockMode=0");
isSPI = spiConn.openInputStream();
osSPI = spiConn.openOutputStream();
}catch(IOException ex){
ex.printStackTrace();
}
}
//Proceso de inicializacion de la interfaz serial ***6950 para LED 7 segmentos
void setup(){
//modo normal --por default esta en shutdown mode--
sendCommand(4,1);
//Diplay test off
sendCommand(7,0);
//Establecimiento de un termino de intensidad medio (rango 0-15)
sendCommand(2,8);
//Establecimiento de un comando limite de escaneo
sendCommand(3,5);
//Modo de decodificacion hexadecimal uso standard para display 7-segmentos
sendCommand(1,255);
}
void send(int data){
try{
/*
******************************************************************************
******************************************************************************
*/
String s1 = "<a000000";
StringBuffer sb = new StringBuffer();
sb.append(Integer.toHexString(data));
if (sb.length() < 2) {
sb.insert(0, '0'); // se aparea con un cero si es necesario
}
String s2=sb.toString();
s1+=s2;
String s3=">";
s1+=s3;
osSPI.write(s1.getBytes());
osSPI.flush();
System.out.println("sent:" +data);
}catch(IOException ex){
ex.printStackTrace();
}
}
void sendCommand(int command, int value){
send(command);
send(value);
}
void displayNumber(int number){
int character=0;
int registerMem=32;
for (int i=0;i<5;i++){
/*
****************************************************************************
****************************************************************************
*/
character = number % 10;
//Se procede a separar digito a digito para enviarlo
sendCommand(registerMem + i ,character);
number=number/10;
}
}
public void closeSPI() {
try {
isSPI.close();
osSPI.close();
spiConn.close();
}catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
I think I have a null pointer at this line
open spi
javax.microedition.io.ConnectionNotFoundException
- javax.microedition.io.Connec
tor.open(), bci=12
- javax.microedition.io.Connector.open(), bci=3
- javax.micro
edition.io.Connector.open(), bci=2
- fox.Fox$SPICommunicator.openSPI(), bci=11
-
fox.Fox$PortListener.run(), bci=34
sending data SPI CHANNEL
Uncaught exception: java.lang.NullPointerException: 0
- fox.Fox$SPICommunicato
r.send(), bci=102
- fox.Fox$SPICommunicator.sendCommand(), bci=2
- fox.Fox$SPICo
mmunicator.displayNumber(), bci=25
- fox.Fox$PortListener.run(), bci=75
Please try with uppercase. SPI: instead of spi:. I have seen something simular with the COM/com ports.
Thank you very much for your reply.Did not work.Same problem
spiConn = (SpiConnection) Connector.open("SPI:0;baudrate=100;clockMode=0");
Hello,
I think you are getting ConnectionNotFoundException because the device is not connected. If then the Connector.open() method throws exception it doesn't return the connection. And then you get NullPointerException because you are trying to operate on the connection reference which is null.
If you have the SPI device that your PCB is going to communicate with it would be the best to connect it to the developer's board you are using now.
Best regards,
Bartłomiej